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 2008 Forums
 Transact-SQL (2008)
 Using IF ELSE STATEMENT

Author  Topic 

Yonkouturko
Yak Posting Veteran

59 Posts

Posted - 2013-06-19 : 02:54:53
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

52326 Posts

Posted - 2013-06-19 : 03:05:00
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

59 Posts

Posted - 2013-06-19 : 03:14:15
Does Sql Server 2008 r2 not have IF ELSE STATEMENT?

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

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-06-19 : 03:27:34
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
Go to Top of Page

Yonkouturko
Yak Posting Veteran

59 Posts

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-19 : 03:59:37
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
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-06-19 : 04:34:09
quote:
Originally posted by Yonkouturko

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


welcome

--
Chandu
Go to Top of Page
   

- Advertisement -