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
 need of query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vidhyashri
Starting Member

4 Posts

Posted - 11/15/2012 :  01:02:28  Show Profile  Reply with Quote
I have 2 tables with fields

phrase table with fields phraseid and phrasename.
sample table with sampleid,samplename,phraseid.

phraseid phrasename
1 xxx
2 yyy
sampleid samplename phraseid
1 s1 1
2 s2 1

I need the o/p
phraseid phrasename status
1 xxx true
2 yyy false

Sampleid as 1 i am giving as input in select query, according to that phraseid i need to display the status as true.

can you send the query for the above scenario.

ahmeds08
Aged Yak Warrior

India
667 Posts

Posted - 11/15/2012 :  01:14:22  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
try this one

select distinct p.phraseid,p.phrasename,
case when p.phraseid in(select phraseid from samples) then 'True'
else 'False' end as status from phrase p
left join samples s
on s.phraseid=p.phraseid
Go to Top of Page

vidhyashri
Starting Member

4 Posts

Posted - 11/15/2012 :  01:20:24  Show Profile  Reply with Quote
i got it .
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 11/15/2012 :  05:40:01  Show Profile  Reply with Quote
quote:
Originally posted by ahmeds08

try this one

select distinct p.phraseid,p.phrasename,
case when p.phraseid in(select phraseid from samples where sampleid = @sampleid) then 'True'
else 'False' end as status from phrase p
left join samples s
on s.phraseid=p.phraseid


not quite what OP looks for

the above small tweak is needed to get required output

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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