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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Trouble with DATEDIFF using column names

Author  Topic 

esvenson
Starting Member

1 Post

Posted - 2015-04-07 : 16:07:46
I'm having trouble with a query where I need to find the number of days between two columns named ShippingDate and RequiredDate that also includes a few other columns. I'm confused about how to retrieve other unrelated columns before entering the DATEDIFF clause. Query is below.

Return the OrderID, CustID, ShippedDate, RequiredDate, and the number of days between ShippedDate and RequiredDate
Ordered by the number of days between the Shippeddate and RequiredDate

Thanks in advance!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-04-07 : 16:16:52
SELECT OrderID, CustID, ShippedDate, RequiredDate, DATEDIFF(dd, ShippedDate, RequiredDate) AS DaysDiff
FROM...
...
ORDER BY DaysDiff

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -