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 |
|
Denizen
Starting Member
7 Posts |
Posted - 2009-03-31 : 11:03:17
|
| I have a Membership table that shows me whether a Member has paid by including that person's MemberID and MembershipYear in a row. If they have not paid for that year, these two values won't exist in a row. I want to query the Membership table and if the person has paid for 2009, return either a True or False value that I can use as a boolean flag in asp.net. I'm just not sure how to do this. |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-03-31 : 11:29:58
|
sample data and output will make it more clear.You probably need something like,,select a.col1, a.col2, ind=case when exists(select * from tableB where colA=a.ColB) then 'y' else 'n' endfrom tableA a |
 |
|
|
Denizen
Starting Member
7 Posts |
Posted - 2009-03-31 : 11:55:26
|
| Yup, that's it. Thanks.Just to finish the thought, the whole thing looks like this:SELECT Members.MemberID, Members.FullName, CASE WHEN EXISTS(SELECT * FROM Membership WHERE (Members.MemberID = Membership.MemberID) AND (Membership.MembershipYear Like '2009') AND (Membership.MemberID Like '2300'))THEN 'Y'ELSE 'N'END AS [Paid for 2009]FROM Members-- I've hard coded the MemberID value, but it will come from a drop-down in ASP.Net |
 |
|
|
|
|
|