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
 DateDIFF query help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

w1102157
Yak Posting Veteran

80 Posts

Posted - 08/02/2012 :  05:32:32  Show Profile  Reply with Quote
Hi Guys ,

i am trying to find out the number of days between two dates and i am running the following query

DATEDIFF(d, ElementStartDate, ElementEndDate)

however can i alter thsi query to say if the ElementEndDate is -1 then state no end date?

Lumbago
Norsk Yak Master

Norway
3246 Posts

Posted - 08/02/2012 :  05:57:23  Show Profile  Reply with Quote
For the datediff to work you need to compare two columns with data type date/datetime (unless you're using varchar and relying on implicit conversion which you really shouldn't), and -1 is not a valid date/datetime value.

- Lumbago
My blog-> http://thefirstsql.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
48119 Posts

Posted - 08/02/2012 :  09:44:24  Show Profile  Reply with Quote
quote:
Originally posted by w1102157

Hi Guys ,

i am trying to find out the number of days between two dates and i am running the following query

DATEDIFF(d, ElementStartDate, ElementEndDate)

however can i alter thsi query to say if the ElementEndDate is -1 then state no end date?


Isnt ElementEndDate a datetime field? How can it have a value of -1?


------------------------------------------------------------------------------------------------------
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.05 seconds. Powered By: Snitz Forums 2000