Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
declare @prevrequiredDate as date = '12/22/2014', @requiredDate as date, @actioninfo as varchar(100)select @prevrequiredDate, @requiredDateif (@prevrequiredDate <> @requiredDate) begin select @actioninfo = 'Changed from ' + CONVERT(varchar(10), @prevrequireddate, 10) + ' to ' + CONVERT(varchar(10), @requiredDate, 10) print @actioninfo end
DaveHelixpoint Web Developmenthttp://www.helixpoint.com
gbritton
Master Smack Fu Yak Hacker
2780 Posts
Posted - 2014-12-22 : 10:23:03
@requireDate is never set, so it is NULL, so the condition in the if statement evaluates to false.
helixpoint
Constraint Violating Yak Guru
291 Posts
Posted - 2014-12-22 : 10:30:10
Not true. Put null in there. I need this to eval as a true statementDaveHelixpoint Web Developmenthttp://www.helixpoint.com
ScottPletcher
Aged Yak Warrior
550 Posts
Posted - 2014-12-22 : 17:45:26
if (@prevrequiredDate <> @requiredDate) or (@requiredDate is null)
MuralikrishnaVeera
Posting Yak Master
129 Posts
Posted - 2014-12-29 : 00:21:35
[code]declare @prevrequiredDate as date SET @prevrequiredDate = '12/22/2014' declare @requiredDate as dateSET @requiredDate = NULLdeclare @actioninfo as varchar(100)select @prevrequiredDate, @requiredDateif (@prevrequiredDate <> (ISNULL(@requiredDate,''))) BEGIN select @actioninfo = 'Changed from ' + CONVERT(varchar(10), @prevrequireddate, 10) + ' to ' + CONVERT(varchar(10), ISNULL(@requiredDate,''), 10) PRINT @actioninfo END[/code]---------------Murali KrishnaYou live only once ..If you do it right once is enough.......
gbritton
Master Smack Fu Yak Hacker
2780 Posts
Posted - 2014-12-29 : 09:04:49
quote:Originally posted by helixpoint Not true. Put null in there. I need this to eval as a true statementDaveHelixpoint Web Developmenthttp://www.helixpoint.com
What is "not true"? I see a declaration for the variable. I cannot see anywhere where the variable is set. So, it is most certainly "true" that the the value of the variable is NULL when you test it in the if-statement.Note: you can only test for null values using the "IS NULL" or "IS NOT NULL" expressions.