Connecting Tech Pros Worldwide Help | Site Map

insert into - add multiple values in a column

  #1  
Old June 22nd, 2009, 10:02 AM
Site Addict
 
Join Date: Feb 2007
Posts: 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
  #2  
Old June 22nd, 2009, 02:30 PM
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,063
Provided Answers: 2

re: insert into - add multiple values in a column


Expand|Select|Wrap|Line Numbers
  1. INSERT INTO Orders(OrderID, Items) VALUES ____+________
  #3  
Old June 22nd, 2009, 05:28 PM
ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,914
Provided Answers: 1

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
  #4  
Old June 26th, 2009, 05:16 AM
nbiswas's Avatar
Newbie
 
Join Date: May 2009
Location: India
Posts: 10

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
inserting multiple values from one table to another tables tb1 answers 2 January 8th, 2008 03:28 PM
INSERT into + null deejayquai answers 3 March 27th, 2007 12:15 AM
Order by in a INSERT INTO..SELECT pb648174 answers 29 April 25th, 2006 06:45 PM
Inserting multiple rows with a single INSERT INTO hartley_aaron@hotmail.com answers 2 July 23rd, 2005 09:31 AM
insert into table-Primary key error Cliff answers 1 July 20th, 2005 03:45 AM