Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

issue with converting row data to column

Status
Not open for further replies.

SqlHunter

Programmer
Jun 3, 2004
166
US
Here basically iam stuck with issue of converting row data to column
.
tbl_emp_codes


tek_id emp_id emp_name emp_code
AK-0000002 39569 Rek Broc 99504
AK-0000002 39566 Rek Broc 99501
AK-0000002 39568 Rek Broc 99503
AK-0000002 39570 Rek Broc 99505
AK-0000002 39571 Rek Broc 99506
AK-0000002 39572 Rek Broc 99507
AK-0000002 39573 Rek Broc 99508
AK-0000002 39580 Rek Broc 99515
AK-0000002 39581 Rek Broc 99516
AK-0000002 39582 Rek Broc 99517
AK-0000002 39567 Rek Broc 99502
AK-0000003 39566 Tina Stee 99501
AK-0000003 39580 Tina Stee 99515
AK-0000003 39573 Tina Stee 99508
AK-0000003 39572 Tina Stee 99507
AK-0000003 39569 Tina Stee 99504
AK-0000003 39568 Tina Stee 99503
AK-0000003 39567 Tina Stee 99502
AK-0000003 39582 Tina Stee 99517
AK-0000003 39610 Tina Stee 99567
AK-0000003 39583 Tina Stee 99518
AK-0000003 39581 Tina Stee 99516
AK-0000003 39619 Tina Stee 99577
AK-0000004 39601 Trans Priory 99556
AK-0000004 39635 Trans Priory 99603


Above is the table I have got and Iam selecting for each tek_id and then inserting to emp_id1 the first emp_id,the first emp_code to emp_code1 and
second emp_id to emp_id2,the second emp_code to emp_code2..like that

They have already 15 emp_code and emp_id and they are pretty sure that it won't exceed that or is there any way to create colum according to the selection here
basically whenever there is 6th emp_code then only create 6 emp_code columns


Table-tbl_tek_emp

tek_id emp_id1 emp_code1 emp_id2 emp_code2 emp_id3 emp_code3......emp_code15
AK-0000002 39569 99504 39566 9501 39568 99503
 
The existing table is the proper table design.

What benifit are you trying to acheive by making this change?

Denny

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(My very old site)
 
These data needs to be converted to these tables.This is a requirement
 
You'll need to use a cursor to spread the data out the way that you want. Probably a cursor within a cursor.

Denny

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(My very old site)
 
Tell them no that it would be a bad practice and will make data access much more difficult and less efficient. Sometimes you have to tell the customer no.

Should that fail:
Crosstab Query - PART I (Code Generator) faq183-5269
Crosstab Query - PART II (Dynamic Execution) faq183-5278



Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top