473,383 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Stored procedure to transfer the data of one row to a single column

Hi friends,

I have a table structure like this in SQL sever 2000.

i want a stored procedure to transfer the data from "tblSurvey" table
to "tblRespondent" table.

Table - tblSurvey
----------------------------------------------------
columnHeading col1 col2 col3 col4 col5 |
----------------------------------------------------
Res1 12 11 13 111 888 |
Res2 1A 1B 1c 1d 8E |
..
..

--------------------------------------------------

I want to store this as a single column like this

Table - tblRespondent
----------------------
Respondent QuesID
----------------------
Res1 12
Res1 11
Res1 13
Res1 111
Res1 888

Res2 1A
Res2 1B
Res2 1c
Res2 Id
Res2 8E
------------------

any method is there to split the row data into column through stored
procedure
we can do this using recordset operation but it is very slow because
the table row has
more than 300 columns, I hope u understand my problem..
thanks
Arun

Nov 17 '06 #1
3 1542
This is neither a c# nor CLI question - you should really move this to one
of the sqlserver ngs

BTW: 300 columns in a table... ouch...

Marc
Nov 17 '06 #2
Hi Arun,

I agree with Marc - it's probably time for some normalization, or at least
vertical partitioning.

--
Dave Sexton

<it***********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi friends,

I have a table structure like this in SQL sever 2000.

i want a stored procedure to transfer the data from "tblSurvey" table
to "tblRespondent" table.

Table - tblSurvey
----------------------------------------------------
columnHeading col1 col2 col3 col4 col5 |
----------------------------------------------------
Res1 12 11 13 111 888 |
Res2 1A 1B 1c 1d 8E |
.
.

--------------------------------------------------

I want to store this as a single column like this

Table - tblRespondent
----------------------
Respondent QuesID
----------------------
Res1 12
Res1 11
Res1 13
Res1 111
Res1 888

Res2 1A
Res2 1B
Res2 1c
Res2 Id
Res2 8E
------------------

any method is there to split the row data into column through stored
procedure
we can do this using recordset operation but it is very slow because
the table row has
more than 300 columns, I hope u understand my problem..
thanks
Arun

Nov 17 '06 #3
SELECT id, 'col1', col1 FROM tblSurvey
UNION ALL SELECT id, 'col2', col2 FROM tblSurvey
/* snip */
UNION ALL SELECT id, 'col300', col300 FROM tblSurvey

..... (aarrgghh!)

Note you could output the above query as a sneaky one-off hack, such
as:
DECLARE @table sysname, @firstcol sysname
SET @table = 'tblSurvey'
SELECT @firstcol = name
FROM syscolumns
WHERE id = OBJECT_ID(@table)
AND colorder =1
SELECT CASE colorder WHEN 2 THEN '' ELSE 'UNION ALL ' END + 'SELECT ['
+ @firstcol + '], ''' + name + ''',[' + name + '] FROM [' + @table +
']'
FROM syscolumns
WHERE id = OBJECT_ID(@table)
AND colorder >= 2

Not one to run every day

;-p

Nov 17 '06 #4

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

Similar topics

3
by: Jarrod Morrison | last post by:
Hi All I have a stored procedure with a temporary table that with two columns in it. The first column contains 3 digit numbers and the second column some descriptive data. I was wondering what...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
13
by: dawatson833 | last post by:
I have several stored procedures with parameters that are defined with user defined data types. The time it takes to run the procedures can take 10 - 50 seconds depending on the procedure. If I...
5
by: Rob Wire | last post by:
For the code below, how could I add an item in the drop down lists for both company and location to be an "All" selection that would send to the stored proc. spRptAttachments a value of "%" so...
5
by: Andy G | last post by:
I have a registration page that captures 75% of the users data. After they enter that info they are redirected to one of two pages depending on how they answered a question on the registation...
1
by: .Net Sports | last post by:
i have an aliased column in an sql statement that works fine when displaying its output in a datagrid, but when I transfer the sql statement into a stored procedure , the datagrid can't see it. I...
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
2
by: Roger | last post by:
I have a stored procedure running on DB2 V7 Z/os calling a COBOL program to do some inserts. The stored procedure have 3 input columns and one column is of varchar(32648) The stored procedure is...
9
by: fniles | last post by:
I am using VB.NET 2003 and SQL2000 database. I have a stored procedure called "INSERT_INTO_MYTABLE" that accepts 1 parameter (varchar(10)) and returns the identity column value from that table....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.