473,547 Members | 2,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Insert into multiple rows instead of one comma-delimited list?

Hi, all:

I have a form which lets users choose more than one value for each question.
But how do I insert each value as a separate row in my table (instead of
having the values submitted as a comma-delimited list)?

Thanks for your help.

J
Jul 20 '05 #1
2 16751
J
SQL Server does not support arrays.
Look at this example helps you to solve the problem

CREATE PROCEDURE dbo.FAQ_ListToT able
@cslist VARCHAR(8000),
@tablename SYSNAME AS
BEGIN
DECLARE @spot SMALLINT, @str VARCHAR(8000), @sql VARCHAR(8000)

WHILE @cslist <> ''
BEGIN
SET @spot = CHARINDEX(',', @cslist)
IF @spot>0
BEGIN
SET @str = CAST(LEFT(@csli st, @spot-1) AS INT)
SET @cslist = RIGHT(@cslist, LEN(@cslist)-@spot)
END
ELSE
BEGIN
SET @str = CAST(@cslist AS INT)
SET @cslist = ''
END
SET @sql = 'INSERT INTO '+@tablename+'
VALUES('+CONVER T(VARCHAR(100), @str)+')'
EXEC(@sql)
END
END

CREATE TABLE #vals (id INT)
EXEC FAQ_ListToTable '1,2,3,5,7,8',' #vals'
SELECT * FROM #vals
drop proc FAQ_ListToTable
"J Belly" <me@privacy.net > wrote in message
news:bo******** *****@ID-75963.news.uni-berlin.de...
Hi, all:

I have a form which lets users choose more than one value for each question. But how do I insert each value as a separate row in my table (instead of
having the values submitted as a comma-delimited list)?

Thanks for your help.

J

Jul 20 '05 #2
Insert Into <table>
Select <value1>
UNION
SELECT <Value2>
.....
UNION
SELECT <Value n>

HTH
Roji

"J Belly" <me@privacy.net > wrote in message
news:bo******** *****@ID-75963.news.uni-berlin.de...
Hi, all:

I have a form which lets users choose more than one value for each question. But how do I insert each value as a separate row in my table (instead of
having the values submitted as a comma-delimited list)?

Thanks for your help.

J

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
33288
by: RotterdamStudents | last post by:
Hello there, i have a strange problem. I can't get php to insert multiple rows at once in a MySQL database. I use the $sql = "INSERT INTO database (a,b,c,d,e) VALUES ('$a', '$b' ,'$c', '$d', '$e')"; I want to insert 5 rows at a time in the database, but it only inserts every 5th record. For example: 1. AA
3
3028
by: Jason | last post by:
The best way to explain this is by example. I have a source table with many columns. Source SYMBOL EXCHANGE_NAME CUSIP TYPE ISSUE_NAME
4
5124
by: fip | last post by:
Hi, On DB2 7.1.2 on MVS OS 390, when I tried to do an insert with multiple row contents in the values clause: insert into table11 values('aaaa', 'fa'), ('bbbb', 'fb') I got the error: DB21034E The command was processed as an SQL statement because it
32
14771
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if ((someString.IndexOf("something1",0) >= 0) || ((someString.IndexOf("something2",0) >= 0) ||
0
2002
by: Patrick.O.Ige | last post by:
I have a datagrid with checkboxes.. When a user clicks one check box and clicks the delete button it deletes that ROw. There another situation when a user clicks multiple rows so i had to loop throug the rows like so:- foreach (DataGridItem i in DataGrid1.Items) { CheckBox deleteChkBxItem = (CheckBox) i.FindControl ("DeleteRow"); if...
2
3674
by: wombat53 | last post by:
Hi Group Are there any DB2 UDB ESE DPF V8.2 users exploiting "buffered inserts" (BIND parm INSERT BUF) *and* "multi-row INSERTS" (many rows associated with the VALUES clause of the INSERT to minimize number of calls to the RDMBS engine) in an SQL PL Stored Procedure? I ask, as the latter would imply embedded DYNAMIC SQL due to potentially...
4
2896
by: Michel Esber | last post by:
Hello, Environment: db2 V8 FP 13 LUW Our application currently uses: insert into table values ('A'),('B'),...('Z') We have used CLI arrays inserts (1000 array and commit size) and managed to insert 1 Million rows into an empty table in 32 seconds. Our
4
5650
by: edtrvl | last post by:
Hi there, I'm trying to insert multiple rows from a table format web form into multiple rows in a SQL table, (1 row for 1 row). Any help would be greatly appreciated, thanks in advance Here's the code of my page: <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%> <!--#include file="../../../Connections/BILLING.asp" --> <% FEQUIPID =...
58
8018
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also the parts section an i seem to be having trouble. When i try to insert into the parts section i get the error Invalid character value for cast...
2
1430
daJunkCollector
by: daJunkCollector | last post by:
Hey, I have a simple web app that requires the user to click a text link to add a section to the form. As you will see from the following code (PHP/mySQL), the link inserts a row into the database table. The problem is that, during testing, sometimes when I click the link, two rows are added instead of only one. I only want one row to be added. ...
0
7437
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7703
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6032
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5362
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3493
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3473
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1923
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.