Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

SQL Server: Insert columns as rows without using a cursor

$
0
0

I have a table that for each row, it has 5 columns for each sale rep that could be listed.

I need to insert each of the reps as a new row into a secondary table.

For example I would have:

Order Num, Rep1, Rep2, Rep3, Rep4, Rep5

and I want

Order Num, Rep1

Order Num, Rep2

Order Num, Rep3

Order Num, Rep4

Order Num, Rep5

I can do this with a cursor but I was wondering how to do this with just set based SQL.

I thought of doing 5 different inserts, one for each Rep but I'm wondering if there is a way to do it with just one.

Any thoughts?

Thanks All!


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>