SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Loop Function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

funk.phenomena
Posting Yak Master

Canada
120 Posts

Posted - 01/17/2013 :  15:35:10  Show Profile  Reply with Quote
Hi all - I'm ussing SSMS 2008 and have the following table (there's about 100 rows):

USER_ID BALLOT_COUNT
jsmith 5
mdoe   3
JRoberts 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 

mdoe
mdoe
mdoe

JRoberts
JRoberts


SELECT USER_ID, BALLOT_COUNT FROM TABLE1


Edited by - funk.phenomena on 01/17/2013 15:56:39

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 01/17/2013 :  15:49:42  Show Profile  Reply with Quote
DECLARE @Table TABLE (UserID varchar(10),Ballot_Count int)
INSERT INTO @Table
VALUES
('jsmith', 5),
('mdoe', 3),
('JRoberts', 2)

SELECT UserID
FROM @Table t
CROSS 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.num

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2869 Posts

Posted - 01/17/2013 :  16:33:39  Show Profile  Reply with Quote
What's wrong with my solution?

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

funk.phenomena
Posting Yak Master

Canada
120 Posts

Posted - 01/18/2013 :  09:29:07  Show Profile  Reply with Quote
Works! Thanks!
Go to Top of Page

subashseo
Starting Member

Barbados
4 Posts

Posted - 01/19/2013 :  07:15:40  Show Profile  Reply with Quote
unspammed
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000