SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Question about the YEAR Function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

TWD38
Starting Member

7 Posts

Posted - 05/10/2012 :  11:59:32  Show Profile  Reply with Quote
SQL is telling me that my use of the YEAR function is not valid.
Can anyone tell me why? How can I query for multiple years?

Here is my query:



SELECT   a.RECIP_SSN_NBR,
     
         char(b.recip_retir_dt, USA), 
         sum(a.OBLIG_TOT_AMT)  AS TOTAL 
         year(a.OBLIG_CREAT_DT) 
         
         
FROM     DSNP.PR01_T_OBLIG_CMPNT a, 
         DSNP.PR01_T_RECIP_SYS b 
      
         
         
WHERE    a.RECIP_SSN_NBR=b.RECIP_SSN_NBR 




AND      a.CMPNT_TYPE_CD = '42' 
AND      YEAR(a.OBLIG_CREAT_DT) IN (2009, 2010, 2011)
and      b.benef_stat_cd in ('AC', 'DP')
and      b.recip_retir_dt2 is NULL
and      b.benef_seq_nbr = 1


GROUP BY 

a.RECIP_SSN_NBR,

         b.recip_retir_dt,  
year(a.OBLIG_CREAT_DT)



The query works if I use = to a specific year, but with multiple years.

TWD38
Starting Member

7 Posts

Posted - 05/10/2012 :  12:01:39  Show Profile  Reply with Quote
Disregard. I'm an idiot. I just noticed the missing comma which was generating the complaint in my SELECT statement.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48093 Posts

Posted - 05/10/2012 :  12:03:23  Show Profile  Reply with Quote
quote:
Originally posted by TWD38

SQL is telling me that my use of the YEAR function is not valid.
Can anyone tell me why? How can I query for multiple years?

Here is my query:



SELECT   a.RECIP_SSN_NBR,
     
         char(b.recip_retir_dt, USA), 
         sum(a.OBLIG_TOT_AMT)  AS TOTAL 
         year(a.OBLIG_CREAT_DT) 
         
         
FROM     DSNP.PR01_T_OBLIG_CMPNT a, 
         DSNP.PR01_T_RECIP_SYS b 
      
         
         
WHERE    a.RECIP_SSN_NBR=b.RECIP_SSN_NBR 




AND      a.CMPNT_TYPE_CD = '42' 
AND      YEAR(a.OBLIG_CREAT_DT) IN (2009, 2010, 2011)
and      b.benef_stat_cd in ('AC', 'DP')
and      b.recip_retir_dt2 is NULL
and      b.benef_seq_nbr = 1


GROUP BY 

a.RECIP_SSN_NBR,

         b.recip_retir_dt,  
year(a.OBLIG_CREAT_DT)



The query works if I use = to a specific year, but with multiple years.



is this t-sql?
highlighted doesnt seems to be inline with t-sql syntax
if you're not using MS SQL Server please post this in relevant forum at www.dbforums.com
This forum is specifically for SQL Server

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000