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
 If Update Error in Read Column Name With Variable

Author  Topic 

kok_sheng2000
Starting Member

10 Posts

Posted - 2012-05-07 : 04:04:41
Thanks for khtan, another problem faced ... ==||

WHILE @Counter < @ColumnCount
BEGIN
Set @Counter = @Counter + 1
SELECT @StringColumn = (SELECT COL_NAME(OBJECT_ID(@TableName), @Counter) AS 'Column_Name')
IF Update(@StringColumn)
-- Execute Some Code Here
END

With Code Above, I want to Loop every Columm in a Table and Check
update using IF Update(@StringColumn), but cant Execute, The message show
"Incorrect syntax near '@StringColumn'." .Please Help ...

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-05-07 : 07:07:58
Is UPDATE a user-defined function? If so, you will need to use it as dbo.Update as in "IF dbo.Update(@StringColumn) = 1".

If it is not a UDF, then SQL Server is interpreting that as the UPDATE keyword (as in UPDATE the data in a table).

If Update is a UDF, it is not a great name because UPDATE is a reserved keyword. I would change it to something else if at all possible.
Go to Top of Page
   

- Advertisement -