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 2008 Forums
 Transact-SQL (2008)
 how to coalesce smalldatetime and date

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2013-08-08 : 07:15:19
COALESCE([t1].[DateCancelled],[t1].[CompletionDate]) [TheDate]

I am getting the following error:
The conversion of a date data type to a smalldatetime data type resulted in an out-of-range value

Dave
Helixpoint Web Development
http://www.helixpoint.com

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-08-08 : 07:30:11
COALESCE(CAST(t1.DateCancelled AS DATE), CAST(t1.CompletionDate AS DATE)) AS TheDate



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-08-08 : 07:45:01
whats the datatype of DateCancelled and CompletionDate?

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

sivadss2007
Starting Member

18 Posts

Posted - 2013-08-28 : 09:44:18
Use the caste function to convert to datetime for 'datecancelled' and 'completiondate'

P.Siva
Go to Top of Page

ShivaKrishna
Starting Member

20 Posts

Posted - 2013-08-28 : 11:34:24

One of the date is in smalldatetime datatype but other is not in smalldatetime and so it might resulted in error
use the following:

COALESCE(CAST(t1.DateCancelled AS smalldatetime), CAST(t1.CompletionDate AS smalldatetime)) AS TheDate
Go to Top of Page

VeeranjaneyuluAnnapureddy
Posting Yak Master

169 Posts

Posted - 2013-08-29 : 08:42:49
COALESCE(CAST(CONVERT(VARCHAR,t1.DateCancelled) AS SMALLDATETIME),
CAST(CONVERT(VARCHAR,t1.CompletionDate) AS SMALLDATETIME))AS TheDate

veeranjaneyulu
Go to Top of Page
   

- Advertisement -