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 - 2013-01-17 : 15:35:10
|
Hi all - I'm ussing SSMS 2008 and have the following table (there's about 100 rows):USER_ID BALLOT_COUNTjsmith 5mdoe 3JRoberts 2 I'd like to output the usernames on multiple lines based on the ballot count. Any idea how I can acheive this?jsmith jsmith jsmith jsmith jsmith mdoemdoemdoeJRobertsJRobertsSELECT USER_ID, BALLOT_COUNT FROM TABLE1 |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2013-01-17 : 15:49:42
|
DECLARE @Table TABLE (UserID varchar(10),Ballot_Count int)INSERT INTO @TableVALUES('jsmith', 5),('mdoe', 3),('JRoberts', 2)SELECT UserIDFROM @Table tCROSS JOIN -- use a tally table here - table that has a lot of numbers in it, this is for demo purposes only( VALUES (1),(2),(3),(4),(5)) a(num)WHERE t.Ballot_Count >= a.numJimEveryday I learn something that somebody else already knew |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2013-01-17 : 16:33:39
|
What's wrong with my solution?JimEveryday I learn something that somebody else already knew |
|
|
funk.phenomena
Posting Yak Master
121 Posts |
Posted - 2013-01-18 : 09:29:07
|
Works! Thanks! |
|
|
subashseo
Starting Member
4 Posts |
Posted - 2013-01-19 : 07:15:40
|
unspammed |
|
|
|
|
|