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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help with while loop condition

Author  Topic 

SexyChick
Starting Member

6 Posts

Posted - 2010-05-13 : 16:49:10
I have inherited a sproc withe the following while loop condition.


While ( Select FileName
From #FileCheck ) = 'File Not Found'

Can someone explain to me how it works? There could be several records in the table variable #FileCheck. Does it just evaluate the first row?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-13 : 17:27:04
There can only be one row in that table at all times, otherwise it'll fail:
quote:

Msg 512, Level 16, State 1, Line 4
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.



The developer could have just used a variable instead of a temp table.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -