October 27, 2010 at 5:16 am
declare @to_date datetime
set @to_date= ' '
print @to_date
it will return 1st jan 1900....why?... any help?.. we cant assign this '' value to a datetime variable?
October 27, 2010 at 6:22 am
'' would be character data so it would not be compatiable with datetime,.
SQL server uses 1 jan 1900 instead, various other systems use other dates to act as a 'placeholder' for missing dates
October 27, 2010 at 6:24 am
MonsterRocks (10/27/2010)
declare @to_date datetimeset @to_date= ' '
print @to_date
it will return 1st jan 1900....why?... any help?.. we cant assign this '' value to a datetime variable?
sql will do an implicity conversion of empty string to zero...and zero is the integer value of the first date in SQL server: 1900-01-01 00:00:00.000
Lowell
October 27, 2010 at 8:16 am
It sounds to me that what you want is a NULL. If so, just leave it undefined.
Or, if the value is being passed in:
declare @to_date datetime;
set @to_date= NullIF(' ', ' ');
print @to_date;
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
October 29, 2010 at 3:56 am
thanks a lot for ur valuable ideas.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply