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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 CASE STATEMENT SYNTAX

Author  Topic 

Blessed1978
Yak Posting Veteran

97 Posts

Posted - 2014-04-09 : 21:36:37
is this a correct syntax to populate a files name PHONES

case when(d.phone = (SELECT phone from CALLS where exists(select home_phone, mobile, toll_free from CALLS2) Then 1 END 'PHONES'

VeeranjaneyuluAnnapureddy
Posting Yak Master

169 Posts

Posted - 2014-04-10 : 00:58:38
case when d.phone IN (SELECT phone from CALLS where exists(select home_phone, mobile, toll_free from CALLS2)) Then 1 END 'PHONES'

Veera
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-04-14 : 08:00:44
quote:
Originally posted by VeeranjaneyuluAnnapureddy

case when d.phone IN (SELECT phone from CALLS where exists(select home_phone, mobile, toll_free from CALLS2)) Then 1 END 'PHONES'

Veera



The syntax is correct but it really smells bad. Can we see the whole query? I have a feeling it can be done better.
Go to Top of Page

wided
Posting Yak Master

218 Posts

Posted - 2014-04-17 : 04:18:50
case when d.phone IN (SELECT phone from CALLS where exists(select home_phone, mobile, toll_free from CALLS2)) Then 1 ELSE 'PHONES' END
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-04-17 : 06:17:27
Not one of you bothered to check the query.
The exists clause will always be true as long there are rows in Calls2 table since there is no predicate in the query.
Also, you have a predicate against Calls table.

Is this what you want?
CASE
WHEN EXISTS (SELECT * FROM dbo.Calls WHERE d.Phone IN (Home_Phone, Mobile, Toll_Free)) THEN 1
END AS [Phone]



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-04-17 : 08:14:43
quote:
Originally posted by wided

case when d.phone IN (SELECT phone from CALLS where exists(select home_phone, mobile, toll_free from CALLS2)) Then 1 ELSE 'PHONES' END



That's not a complete query.
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-04-17 : 11:51:48
It seems to be based on another thread: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=193659

And I still don't know what the OP wants and they don't seem to want to supply information to help us understand, so...
Go to Top of Page
   

- Advertisement -