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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SP to return multiple items from 1 record 1

Status
Not open for further replies.

lmohr79

Technical User
Jan 18, 2005
39
US
I'm fairly green with SQL - learned most everything on the fly and have never worked with cursors, but think that this is what I need to do.

Here's a example of the MSSQL table I've been given to work with (Name is the primary key):

Name Reason1 Reason2 Reason 3
Joe 1 0 0
Mike 1 1 0
Susie 0 1 1

The records are inserted from a .NET web app, and the "reasons" are just boolean (from check boxes).

What has been requested is a report showing when the reason is 1 - so from my example, here's what the report would look like (done in Crystal 8.5):

Joe - Reason 1
Mike - Reason 1
Mike - Reason 2
Susie - Reason 2
Susie - Reason 3

Any help would be appreciated!!!
 
Code:
select Name, 'Reason 1' as Reason from blah where Reason1 = 1
union all
select Name, 'Reason 2' from blah where Reason2 = 1
union all
select Name, 'Reason 3' from blah where Reason3 = 1

------
[small]<this is sig>
select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')
</this is sig>[/small]
[banghead]
 
Thank you!!! this worked like a dream!

Plus I really like your "smiley" - I feel like banging my head against the was a lot of the time!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top