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
 Set more that one var from Select stament

Author  Topic 

shifis
Posting Yak Master

157 Posts

Posted - 2006-03-08 : 19:23:18
I have the next code:

declare @SaldoNuevo decimal(9,2)

SET @SaldoActual =
( SELECT SALDO FROM TBSALDOS
WHERE ID=@ID
)

But I want to do a select that return 3 field and set the values to three variables.

declare @SaldoNuevo decimal(9,2)
declare @LastName varchar(30)
declare @Name varchar(30)


SET @SaldoActual, @LastName, @Name =
( SELECT SALDO, LASTNAME, NAME
FROM TBSALDOS
WHERE ID=@ID
)

Hope you undestand my English

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-08 : 19:24:20
[code]SET @SaldoActual = SALDO, @LastName = LASTNAME, @Name = NAME
FROM TBSALDOS
WHERE ID=@ID[/code]

----------------------------------
'KH'


Go to Top of Page

shifis
Posting Yak Master

157 Posts

Posted - 2006-03-08 : 19:35:27
I got this error:

Server: Msg 170, Level 15, State 1, Line 39
Line 39: Incorrect syntax near ','.
Go to Top of Page

shifis
Posting Yak Master

157 Posts

Posted - 2006-03-08 : 19:39:56
Got it!

Is SELECT instead of SET

SELECT @SaldoActual = SALDO, @LastName = LASTNAME, @Name = NAME
FROM TBSALDOS
WHERE ID=@ID

Thanks!!

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-08 : 19:44:52
quote:
Originally posted by shifis

I got this error:

Server: Msg 170, Level 15, State 1, Line 39
Line 39: Incorrect syntax near ','.




Sorry it should be SELECT instead of SET

----------------------------------
'KH'


Go to Top of Page
   

- Advertisement -