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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 CASE STATEMENT SYNTAX
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Blessed1978
Yak Posting Veteran

60 Posts

Posted - 04/09/2014 :  21:36:37  Show Profile  Reply with Quote
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

India
165 Posts

Posted - 04/10/2014 :  00:58:38  Show Profile  Reply with Quote
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
Aged Yak Warrior

662 Posts

Posted - 04/14/2014 :  08:00:44  Show Profile  Reply with Quote
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

199 Posts

Posted - 04/17/2014 :  04:18:50  Show Profile  Reply with Quote
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

Sweden
30217 Posts

Posted - 04/17/2014 :  06:17:27  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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
Aged Yak Warrior

662 Posts

Posted - 04/17/2014 :  08:14:43  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 04/17/2014 :  11:51:48  Show Profile  Reply with Quote
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
  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