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
 Transact-SQL (2000)
 Arrary to table

Author  Topic 

p0rt21
Starting Member

3 Posts

Posted - 2003-05-10 : 07:26:08
Hey

Bit of a noob question

how can i insert an array into its own row

insert into sold (price,product_id) values ('3, 5','2701, 2763')


Cheers
p0rt21

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2003-05-10 : 08:43:11
quote:

Hey

Bit of a noob question

how can i insert an array into its own row

insert into sold (price,product_id) values ('3, 5','2701, 2763')


Cheers
p0rt21

u can use the function csvtoint i guess :
http://www.sqlteam.com/item.asp?ItemID=11499



Expect the UnExpected
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-05-10 : 10:24:41
the way to insert multiple rows of values into a table is:


insert into sold (price, product_id)
SELECT price, product_id
from
SomeTable

if the data is already in a table. this is the alternate format for INSERT INTO, rather than using VALUES. YOu can select from any table into another, as long as the field types and all that match up.

you can create your own "fake table" of values like this:

select 3,5 union
select 2701, 2763 union
select 4,6 union
select 5,7

and so on

Thus, in your specific example, you could do:

insert into sold (price,product_id)
select 3, 5 union
select 2701, 2763

I hope this helps a little.



- Jeff
Go to Top of Page

p0rt21
Starting Member

3 Posts

Posted - 2003-05-10 : 19:18:54
thanks for that

but

the array is coming from a hiddenfield in a form

im using asp

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-05-10 : 20:45:04
http://www.sqlteam.com/item.asp?ItemID=2652

Or you can try some of the other articles listed here:

http://www.sqlteam.com/SearchResults.asp?SearchTerms=csv

Go to Top of Page

p0rt21
Starting Member

3 Posts

Posted - 2003-05-10 : 21:12:42
thanks for that but i don't really understand it

Go to Top of Page

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2003-05-11 : 01:56:15
You can tell us what you do know and we'll recommend some reading materials.

Go to Top of Page
   

- Advertisement -