Connecting Tech Pros Worldwide Help | Site Map

insert into - add multiple values in a column

Site Addict
 
Join Date: Feb 2007
Posts: 553
#1: Jun 22 '09
Hi

How do i write multiple values in a single column, using INSERT INTO

I have a listbox and i want all the selected values from that listbox inserted into a table column

INSERT INTO Orders(OrderID, Items) VALUES ____?????________

Do i need to run the above statement in a loop?

Thanks
qi
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,076
#2: Jun 22 '09

re: insert into - add multiple values in a column


Expand|Select|Wrap|Line Numbers
  1. INSERT INTO Orders(OrderID, Items) VALUES ____+________
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#3: Jun 22 '09

re: insert into - add multiple values in a column


If you need to have all the selected from your listbox in different rows, yes you need to issue multiple insert statements.


--- CK
nbiswas's Avatar
Newbie
 
Join Date: May 2009
Location: India
Posts: 30
#4: Jun 26 '09

re: insert into - add multiple values in a column


As far as I understand, the problem is something like this.

For Order Id 1, there can be 3 Items(say Item1,Item2,Item3)
For Order Id 2, there can be 5 Items(say Item 1.. Item5, all are comma seperated).


Next you want to insert the values into your database table

So the output will be like

TblOrders

OrderID Items
---------- --------
1 Item1,Item2,Item3

2 Item1,Item2,Item3,Item4,Item5


If that is supposed to be the case, handle all the list box items from your Frontend applications all at a time.

I mean to say before passing to the SQL QUERY, you should send the values as, 1 for OrderId filed while Item1,Item2,Item3 for Item field.

So in that case the SQL STATEMENT will be

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO Orders(OrderID, Items) VALUES (1,' Item1,Item2,Item3');
You don't have to write any loop in the STORED PROC . Handle from your Frontend application.


Hope this helps.
Reply

Tags
insert into