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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SELECTING multiple field values into variables

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-12-11 : 09:18:54
Simon writes "In a stored proc, is there any way to select several field values from the same row into multiple variables?

The command I envisage is:

SELECT Field1, Field2, Field3 INTO @fld1, @fld2, @fld3
FROM tblWorksOrders
WHERE WorksOrder = @WorksOrder

I get a syntax error when I try to run this.

Surely there must be an easy way to do this without resorting to CURSORS and FETCH or writing 3 separate SELECTS?

Advice would be much appreciated! Thanks.

Simon"

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2002-12-11 : 09:35:23
Try:

SELECT @fld1 = Field1, @fld2 = Field2, @fld3 = Field3
FROM tblWorksOrders
WHERE WorksOrder = @WorksOrder

- Jeff
Go to Top of Page
   

- Advertisement -