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
 SQL Server Development (2000)
 Multiple SET from SELECT

Author  Topic 

Knarf180
Starting Member

42 Posts

Posted - 2004-10-29 : 16:32:54
Would it be possible to set multiple variables with one select statement?

The Norm:
SET @test = SELECT * From table1

What I want:

SELECT @test = Field1, @test1 = Field2 From table1

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-10-29 : 16:56:25
this works:

quote:
SELECT @test = Field1, @test1 = Field2 From table1


so what are you asking?

Corey
Go to Top of Page

Knarf180
Starting Member

42 Posts

Posted - 2004-10-29 : 17:03:21
When I did a Print @test I didnt get any results..

Ya sure it works?
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-10-29 : 17:09:55
Run this example...


Declare @myTable table (col1 varchar(100), col2 varchar(100))
Insert Into @myTable
Select col1 = 'col1 data', col2 = 'col2 data'

Declare @test1 varchar(100),
@test2 varchar(100)

Select @test1 = col1, @test2 = col2 from @myTable

Select @test1, @test2


Corey
Go to Top of Page

hgorijal
Constraint Violating Yak Guru

277 Posts

Posted - 2004-10-30 : 01:12:02
is your query "select field1, field2 from table1" returning..
1. any not-null (field2) data at all?
2. is it returning multiple records; with null in field2 of the last record?

If NO in both cases, the @test1 will hold a null.

Hemanth Gorijala
BI Architect / DBA...(yuhoo!!! and now, an "Yak Master")

Exchange a Dollar, we still have ONE each.
Exchange an Idea, we have TWO each.
Go to Top of Page
   

- Advertisement -