Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
funk.phenomena
Posting Yak Master
121 Posts |
Posted - 2012-09-25 : 17:07:11
|
Hi All - I have the following table:USER_ID QTYjsmith 2rbird 4lsantore 1 I need the USER_ID to repeat on multiple lines based on the QTY:USER_IDjsmithjsmithrbirdrbirdrbirdrbirdlsantore Any ideas how I can achieve this? Thanks!SELECT USER_ID FROM TABLE1 |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-09-25 : 17:19:30
|
[code]DECLARE @Foo TABLE (USER_ID VARCHAR(128), QTY INT)INSERT @Foo VALUES('jsmith', 2),('rbird', 4),('lsantore', 1)SELECT T.USER_IDFROM @Foo AS TINNER JOINmaster..spt_values AS AON A.number <= T.Qty aND A.Type = 'P'[/code] |
|
|
funk.phenomena
Posting Yak Master
121 Posts |
Posted - 2012-09-25 : 17:34:20
|
WORKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!! THANKS! |
|
|
|
|
|