Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Debugging a WHILE EXISTS
Message
 
To
02/11/2008 15:16:44
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01358902
Message ID:
01359028
Views:
35
>>Where to select them?
>>You didn't select anything, you just store some data into variables :-)
>>This while is the same as your just I didn't store the variables in EXISTS ()
>>
>>I am not sure what you try to do here. If you give me an example data and desired result maybe there is a solution w/o using cursors.
>
>This is what I had to do:
>
>
>DECLARE @lcField Char(40)
>DECLARE @lcField2 Char(40)
>DECLARE @lnNumero Integer
>DECLARE @lnNumero2 Integer
>DECLARE @loRecord nvarchar(128)
>
>DECLARE loCursor CURSOR LOCAL FOR
>SELECT Numero,Field,Field2 FROM Relation
>
>OPEN loCursor
>FETCH NEXT FROM loCursor INTO @lnNumero,@lcField,@lcField2
>WHILE @@fetch_status = 0
>BEGIN
>   PRINT 'Update Relation '+convert(varchar,@lnNumero)+'.'
>
>   SELECT @lnNumero2=Numero FROM Field WHERE Field=@lcField
>
>   UPDATE Relation SET NoField=@lnNumero2 WHERE Numero=@lnNumero
>
>   SELECT @lnNumero2=Numero FROM Field WHERE Field=@lcField2
>
>   UPDATE Relation SET NoField2=@lnNumero2 WHERE Numero=@lnNumero
>
>   FETCH NEXT FROM loCursor INTO @lnNumero,@lcField,@lcField2
>END
>
Isn't it the same as:
UPDATE Relation SET NoField  = CASE WHEN Field = Field.Field
                                         THEN Field.Numero
                                    ELSE NoField END,
                    NoField2 = CASE WHEN Field = Field.Field2
                                        THEN Field.Numero
                                   ELSE NoField2 END
FROM Relation
INNER JOIN Field ON (Ralation.Field = Field.Field OR Relation.Field2 = Field.Field2)
?
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform