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
 Why doesn't SELECT @columns... work?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-12 : 08:10:03
Bob writes "Your FAQ asks an intersting question:

Why doesn't SELECT @columns FROM @tablname work?

No answer is provided however.

I need to write a stored procedure the passes in a fieldname, retrives next key type int data from that field, increments the field, and returns the NextKey.

Would be nice if something like this worked:
DECLARE @iNext INT
SELECT @iNext = SELECT @columnName FROM Next_Keys WHERE ID = 1
SELECT @iNext = @iNext +1
UPDATE Next_Keys Set @columnName = @iNext WHERE ID = 1
RETURN @iNext

SQL Server 2000 - Win Server 2003
Editing SP from VS2005
TSQL newbe writing first sp"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-08-12 : 08:11:27
Well, when I read the FAQ I find links to three articles on Dynamic SQL that explain how to do what you're looking for. They're about 5 lines down from the question you posted.
Go to Top of Page
   

- Advertisement -