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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 need of query

Author  Topic 

vidhyashri
Starting Member

4 Posts

Posted - 2012-11-15 : 01:02:28
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

737 Posts

Posted - 2012-11-15 : 01:14:22
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 - 2012-11-15 : 01:20:24
i got it .
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-11-15 : 05:40:01
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
   

- Advertisement -