By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,660 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,660 IT Pros & Developers. It's quick & easy.

insert into - add multiple values in a column

100+
P: 553
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
Jun 22 '09 #1
Share this Question
Share on Google+
3 Replies


code green
Expert 100+
P: 1,726
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO Orders(OrderID, Items) VALUES ____+________
Jun 22 '09 #2

ck9663
Expert 2.5K+
P: 2,878
If you need to have all the selected from your listbox in different rows, yes you need to issue multiple insert statements.


--- CK
Jun 22 '09 #3

nbiswas
100+
P: 149
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.
Jun 26 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.