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.
| Author |
Topic |
|
ikhuram
Starting Member
28 Posts |
Posted - 2004-05-26 : 06:22:42
|
| Hiw I can make a dynamic string of string values e.g.,value1 = '001'value2 = '002'value3 = '003'value4 = '004'declare @output varchar(100)select @output = ????HOW TO PUT ALL THESE VALUES IN @output like this@output = '001', '002', '003', '004' |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-05-26 : 06:31:09
|
| Are value1, value2, value3, value4 columns in a table?select '''' + value1 + '''' + ',' + '''' + value2 + '''' + ',' + '''' + value3 + '''' + ',' + '''' + value4 + '''' from mytableDuane. |
 |
|
|
ikhuram
Starting Member
28 Posts |
Posted - 2004-05-26 : 06:36:25
|
| No, These are the values of one column |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-05-26 : 06:48:15
|
| well you'll probably need a dreaded cursor for this.btw - why do you want to do this?Duane. |
 |
|
|
Pethron
Starting Member
10 Posts |
Posted - 2004-05-26 : 07:10:18
|
Maybe this would be the sollution:declare @output varchar(50)declare curex cursor for select myCollumn from MyTabledeclare @fetch int, @value varchar (10)set @fetch = 0open curexwhile @fetch =0begin fetch next from curex into @value set @fetch = @@fetch_Status select @output = isnull(@output,'') + @value endclose curexdeallocate curexselect @output @Duane:What is a dreaded cursor? |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-05-26 : 07:17:32
|
| well I mentioned dreaded cursor because cursors are very cpu expensive - good practice is to try and find a set based solution before trying to use cursors.which is why i asked why this string must be created like ikhuram requested - maybe what he/she is trying to do can be achived by using a simple but clever set based method.Duane. |
 |
|
|
|
|
|
|
|