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 2005 Forums
 Transact-SQL (2005)
 set 2 variables in 1 select

Author  Topic 

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2010-03-11 : 21:59:47
I don't think is possible but let me ask anyway.
Can you set (probably with SELECT(@varX ...)
2 variables in one select statements.
Something like select(@v1,@v2 as (select x,y from tableX)
Thanks.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-03-11 : 22:01:30
[code]
select @v1 = x, @v2 = y
from tablex
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2010-03-11 : 23:35:15
Oh damn, have to rewrite my sql sp now ;P
Thanks.
Go to Top of Page

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2010-03-11 : 23:45:06
Hi.
Sorry i should have specified.
I have a problem with distinct. I get Incorrect syntax near the keyword 'distinct'.
Can it be used with distinct?
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-03-11 : 23:49:17
quote:
Originally posted by sapator

Hi.
Sorry i should have specified.
I have a problem with distinct. I get Incorrect syntax near the keyword 'distinct'.
Can it be used with distinct?



If your distinct query returns one row, you can go ahead!

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2010-03-12 : 00:03:04
OK.Also top 1 i guess.
Also fixed the sql, i had it select @i =( top 1 ds.maxan ....
but it wanted select top 1 @i=(ds.maxan ....
Is this correct?
Thanks
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-03-12 : 00:06:39
quote:
Originally posted by sapator

OK.Also top 1 i guess.
Also fixed the sql, i had it select @i =( top 1 ds.maxan ....
but it wanted select top 1 @i=(ds.maxan ....
Is this correct?
Thanks



Top will fix your issue

The exact syntax is


declare @i int
declare @j int
select top 1 @i=dept_id,@j=salary from Employee
select @i,@j


Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2010-03-12 : 00:12:58
Great.Thanks.
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-03-12 : 00:18:34
quote:
Originally posted by sapator

Great.Thanks.



Welcome

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page
   

- Advertisement -