Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Months between two dates

Author  Topic 

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2013-06-26 : 03:25:36
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

52326 Posts

Posted - 2013-06-26 : 03:28:42
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 - 2013-06-26 : 03:31:02
HI Visakh16

A simple overlook,

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-26 : 03:35:45
welcome

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

- Advertisement -