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)
 table to variable

Author  Topic 

rnbguy
Constraint Violating Yak Guru

293 Posts

Posted - 2007-02-13 : 21:01:46
I think this is possible without using a cursor, i know how to do this with a cursor but would like the set based approach.

I would like to copy a column frrom a table to a variable. so for example

Name
----

Mike
Lary


would go into variable @names

so:

print @names

would bring up Mike Lary

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-02-13 : 21:29:03
http://www.sqlteam.com/item.asp?ItemID=11021

Tara Kizer
Go to Top of Page

rnbguy
Constraint Violating Yak Guru

293 Posts

Posted - 2007-02-13 : 22:39:16
i dont think that link has what im trying to do is go from table to variable... not create or insert into a table
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-02-13 : 22:43:50
[code]
declare @table table
(
[Name] varchar(10)
)

insert into @table
select 'Mike' union all
select 'Lary'

declare @names varchar(1000)

select @names = isnull(@names + ' ', '') + [Name]
from @table

print @names
/*
Mike Lary
*/
[/code]

also see http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx


KH

Go to Top of Page

rnbguy
Constraint Violating Yak Guru

293 Posts

Posted - 2007-02-13 : 22:45:00
perfect... thanx
Go to Top of Page

rnbguy
Constraint Violating Yak Guru

293 Posts

Posted - 2007-02-13 : 23:24:38
i dont know if i should start a new post for this but just quickly how would i use the replace function to replace single quotes with double quotes, i know how to use replace just not in the sense of quotes
Go to Top of Page

rnbguy
Constraint Violating Yak Guru

293 Posts

Posted - 2007-02-13 : 23:48:54
SET QUOTED_IDENTIFIER OFF
GO

worked
Go to Top of Page
   

- Advertisement -