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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-02-28 : 08:19:11
|
| Ron writes "How can I do this without a cursor?I have a single column called 'Number'. How can I run a select statement to insert 10 numbers into the Number Column each with a carrige return or comma?If I do it without a cursor, and the second select returns 1,2,3..9,10, only 10 is placed into the column [Number].Is there a way without using a cursor to insert all 10 results from the select statement into the one column?Thanks,Ron" |
|
|
Nazim
A custom title
1408 Posts |
Posted - 2002-02-28 : 08:21:36
|
| insert into tablename(number)select 1uniounselect 2unioun select 3....select 10HTH-------------------------------------------------------------- |
 |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2002-02-28 : 20:14:42
|
| Ron,I hope that Nazim's solution does what you want, which is to put each value into a new row. However when I read your question, I got this uneasy feeling, because you mention <cr>'s that you want multiple values within one row. I cannot begin to tell you how much this idea concerns me. I spent YEARS maintaing a database that did this and even though the DBMS was designed to handle these, it became a headache when the database became complex.Regardless, if you really, really want to do that, then read this article on COALESCE. I believe you can change the comma to a char(13).Again, PLEASE rethink your approach if this is what you are wanting to do.------------------------GENERAL-ly speaking... |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-02-28 : 20:27:29
|
| >> I got this uneasy feelingYoh!I think that's the expression our friends across the pond use.==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|
|
|