-
Comparing date with NULL values
Hi , I need to compare two date fields in two different tables.One of the field is varchar(8) and other is dateime.When there is a date in one field and NULL in other field , how do I compare these two vales?
-
Comparing date with NULL values (reply)
How about starting by casting your varchar 'date' column as datetime?
------------
Mano at 5/8/01 1:13:56 PM
Hi , I need to compare two date fields in two different tables.One of the field is varchar(8) and other is dateime.When there is a date in one field and NULL in other field , how do I compare these two vales?
-
Comparing date with NULL values (reply)
I tried using Convert(char(8),@var,1)
------------
ItsMeAgain at 5/8/01 1:17:33 PM
How about starting by casting your varchar 'date' column as datetime?
------------
Mano at 5/8/01 1:13:56 PM
Hi , I need to compare two date fields in two different tables.One of the field is varchar(8) and other is dateime.When there is a date in one field and NULL in other field , how do I compare these two vales?
-
Comparing date with NULL values (reply)
declare @DateChar as varchar(8)
declare @DateDate as datetime
set @DateDate = '05/08/01'
set @DateChar = Null
if @DateChar is Null
begin
set @DateChar = '01/01/50'
end
if @DateDate is Null
begin
set @DateChar = '01/01/50'
end
if datediff(day, @DateDate, cast(@DateChar as datetime)) < 0
begin
print 'DateDate is bigger'
end
if datediff(day, @DateDate, cast(@DateChar as datetime)) > 0
begin
print 'DateChar is bigger'
end
if datediff(day, @DateDate, cast(@DateChar as datetime)) = 0
begin
print 'They are the same'
end
------------
at 5/8/01 1:50:23 PM
I tried using Convert(char(8),@var,1)
------------
ItsMeAgain at 5/8/01 1:17:33 PM
How about starting by casting your varchar 'date' column as datetime?
------------
Mano at 5/8/01 1:13:56 PM
Hi , I need to compare two date fields in two different tables.One of the field is varchar(8) and other is dateime.When there is a date in one field and NULL in other field , how do I compare these two vales?
-
Comparing date with NULL values (reply)
Couldn't you use ISNULL for the @DateDate & @DateChar if all that's needed is a comparison of equality.
------------
ItsMeAgain at 5/8/01 2:07:57 PM
declare @DateChar as varchar(8)
declare @DateDate as datetime
set @DateDate = '05/08/01'
set @DateChar = Null
if @DateChar is Null
begin
set @DateChar = '01/01/50'
end
if @DateDate is Null
begin
set @DateChar = '01/01/50'
end
if datediff(day, @DateDate, cast(@DateChar as datetime)) < 0
begin
print 'DateDate is bigger'
end
if datediff(day, @DateDate, cast(@DateChar as datetime)) > 0
begin
print 'DateChar is bigger'
end
if datediff(day, @DateDate, cast(@DateChar as datetime)) = 0
begin
print 'They are the same'
end
------------
at 5/8/01 1:50:23 PM
I tried using Convert(char(8),@var,1)
------------
ItsMeAgain at 5/8/01 1:17:33 PM
How about starting by casting your varchar 'date' column as datetime?
------------
Mano at 5/8/01 1:13:56 PM
Hi , I need to compare two date fields in two different tables.One of the field is varchar(8) and other is dateime.When there is a date in one field and NULL in other field , how do I compare these two vales?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|