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.
| Author |
Topic |
|
kreg
Starting Member
7 Posts |
Posted - 2004-09-11 : 18:07:58
|
| If at the beginning of a loop a variable is Declared, does it not empty the value of the variable. If not, how do I NULL the value of the variables?WHILE @Count > 0BEGIN DECLARE @KSG1 VARCHAR(50) DECLARE @VAL1 VARCHAR(50) SELECT @ksg1 = Description FROM Features WHERE (Uid = @val1) @COUNT = @COUNT -1END |
|
|
gpl
Posting Yak Master
195 Posts |
Posted - 2004-09-11 : 18:19:56
|
quote: Originally posted by kreg If at the beginning of a loop a variable is Declared, does it not empty the value of the variable. If not, how do I NULL the value of the variables?WHILE @Count > 0BEGIN DECLARE @KSG1 VARCHAR(50) DECLARE @VAL1 VARCHAR(50) SELECT @ksg1 = Description FROM Features WHERE (Uid = @val1) @COUNT = @COUNT -1END
It would be better to do this (Im not sure what TSQL does with multiple declarations of a variable)DECLARE @KSG1 VARCHAR(50)DECLARE @VAL1 VARCHAR(50)WHILE @Count > 0BEGIN SET @KSG1 = NULL SET @VAL1 = NULL SELECT @ksg1 = Description FROM Features WHERE (Uid = @val1) SET @COUNT = @COUNT -1END but as we just nulled the @VAL1, it will not find anything as you cannot test for equality with null, you have to check WHERE (Uid IS NULL)Perhaps it would help if you were to describe what you are trying to doGraham |
 |
|
|
kreg
Starting Member
7 Posts |
Posted - 2004-09-11 : 18:27:03
|
| You answered it.. Using the SET statement cures the problem. Thanks for the Reply. |
 |
|
|
|
|
|