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
 Months between two dates
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masond
Constraint Violating Yak Guru

447 Posts

Posted - 06/26/2013 :  03:25:36  Show Profile  Reply with Quote
HI Guys

I am trying to work out , the difference in months between two dates

however i am keep getting the following error message
"Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'AS'."

Any help would be much appreciated


Data type
Dim_Outlet.Open_Date = Varchar(8)
Audit_FDMS_Billing_Fees_Hist.fee_wholesale_date = Date

My query is

SELECT
Audit_FDMS_Billing_Fees_Hist.FDMSAccountNo,
Dim_Outlet.Open_Date,
Audit_FDMS_Billing_Fees_Hist.fee_wholesale_date,
case when DATEDIFF(month,'dim_Outlet.Open_Date','Audit_FDMS_Billing_Fees_Hist.fee_wholesale_date') AS DiffDate
FROM Audit_FDMS_Billing_Fees_Hist
INNER JOIN Dim_Outlet
ON Audit_FDMS_Billing_Fees_Hist.FDMSAccountNo = Dim_Outlet.FDMSAccountNo
where fee_sequence = '32r'
order by FDMSAccountNo

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/26/2013 :  03:28:42  Show Profile  Reply with Quote
why do you need case when here? i think this is enough

SELECT 
Audit_FDMS_Billing_Fees_Hist.FDMSAccountNo,
Dim_Outlet.Open_Date,
Audit_FDMS_Billing_Fees_Hist.fee_wholesale_date,
case when DATEDIFF(month,dim_Outlet.Open_Date,Audit_FDMS_Billing_Fees_Hist.fee_wholesale_date) AS DiffDate 
FROM Audit_FDMS_Billing_Fees_Hist 
INNER JOIN Dim_Outlet 
ON Audit_FDMS_Billing_Fees_Hist.FDMSAccountNo = Dim_Outlet.FDMSAccountNo
where fee_sequence = '32r'
order by FDMSAccountNo


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 06/26/2013 :  03:31:02  Show Profile  Reply with Quote
HI Visakh16

A simple overlook,

Very good obversation :)
Thank you
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/26/2013 :  03:35:45  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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