Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Debugging a WHILE EXISTS
Message
 
To
01/11/2008 17:07:46
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01358902
Message ID:
01358906
Views:
27
>I am trying to debug the following script:
>
>
>
>DECLARE @lcField Char(40)
>DECLARE @lcField2 Char(40)
>DECLARE @lnNumero Integer
>DECLARE @lnNumero2 Integer
>
>WHILE EXISTS (SELECT @lnNumero=Numero,@lcField=Field,@lcField2=Field2 FROM Relation)
>BEGIN
>   PRINT 'Update Relation '+@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
>
>END
>
>
>On the WHILE EXISTS line, there is an error:
>
>"Incorrect syntax near '='."
>
>If I execute the SQL by itself, it works. So, it is a syntax problem with the use of WHILE EXISTS. Anyone would know what has to be adjusted?
DECLARE @lcField Char(40)
DECLARE @lcField2 Char(40)
DECLARE @lnNumero Integer
DECLARE @lnNumero2 Integer

WHILE EXISTS (SELECT 1 FROM Relation)
BEGIN
   SELECT @lnNumero=Numero,@lcField=Field,@lcField2=Field2 FROM Relation
   PRINT 'Update Relation '+@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

END
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