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 2008 Forums
 Transact-SQL (2008)
 Using IF ELSE STATEMENT
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yonkouturko
Yak Posting Veteran

Philippines
57 Posts

Posted - 06/19/2013 :  02:54:53  Show Profile  Reply with Quote
Is It Possible TO Do if else statement in sql server 2008 r2?
ex. i have 2 tables...tbl_customer_records and tbl_Customer_follow_up
data-tbl_customer_records
ID,CID,CompanyName,Address,ContactPerson
date-tbl_customer_Follow_up
ID,CID,Status,Remarks,Companyname,date,time

now the condition is...
IF tbl_customer_records.CID <> tbl_customer_follow_up.CID THEN
Show all Records
End If

i want to know if there is a similar function or method to IF statements...

all suggestion is ok ! thank you people and have a nice day ahead!!!

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 06/19/2013 :  03:05:00  Show Profile  Reply with Quote
sounds like this to me


SELECT CID,CompanyName
FROM tbl_customer_records cr
WHERE NOT EXISTS(
SELECT 1
FROM tbl_customer_Follow_up
WHERE CID = cr.CID)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Yonkouturko
Yak Posting Veteran

Philippines
57 Posts

Posted - 06/19/2013 :  03:14:15  Show Profile  Reply with Quote
Does Sql Server 2008 r2 not have IF ELSE STATEMENT?

btw it worked perfectly Thank You So much!
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2170 Posts

Posted - 06/19/2013 :  03:27:34  Show Profile  Reply with Quote
You can use T-SQL for IF..ELSE statements... But you can directly do as follows...

--1) Correlated Sub Query (posted by visakh's query)

--2) LEFT JOIN
SELECT cr.*
FROM tbl_customer_records cr
LEFT JOIN tbl_customer_follow_up fu ON fu.CID = cr.CID
WHERE cr.CID IS NULL

--3) SET Operator EXCEPT
SELECT CID FROM tbl_customer_records
EXCEPT
SELECT CID FROM tbl_customer_follow_up

--
Chandu

Edited by - bandi on 06/19/2013 03:28:29
Go to Top of Page

Yonkouturko
Yak Posting Veteran

Philippines
57 Posts

Posted - 06/19/2013 :  03:55:31  Show Profile  Reply with Quote
Bandi tnx for that additional information..
help much appreciated!!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 06/19/2013 :  03:59:37  Show Profile  Reply with Quote
quote:
Originally posted by Yonkouturko

Does Sql Server 2008 r2 not have IF ELSE STATEMENT?

btw it worked perfectly Thank You So much!



welcome

yep...it has IF ELSE statement but its not necessary here as showed by the other solutions

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2170 Posts

Posted - 06/19/2013 :  04:34:09  Show Profile  Reply with Quote
quote:
Originally posted by Yonkouturko

Bandi tnx for that additional information..
help much appreciated!!!


welcome

--
Chandu
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.52 seconds. Powered By: Snitz Forums 2000