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.
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_updata-tbl_customer_recordsID,CID,CompanyName,Address,ContactPersondate-tbl_customer_Follow_upID,CID,Status,Remarks,Companyname,date,timenow the condition is... IF tbl_customer_records.CID <> tbl_customer_follow_up.CID THENShow all RecordsEnd Ifi 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 meSELECT CID,CompanyNameFROM tbl_customer_records crWHERE NOT EXISTS(SELECT 1FROM tbl_customer_Follow_upWHERE CID = cr.CID) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
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! |
|
|
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 JOINSELECT cr.*FROM tbl_customer_records crLEFT JOIN tbl_customer_follow_up fu ON fu.CID = cr.CIDWHERE cr.CID IS NULL--3) SET Operator EXCEPTSELECT CID FROM tbl_customer_records EXCEPTSELECT CID FROM tbl_customer_follow_up--Chandu |
|
|
Yonkouturko
Yak Posting Veteran
59 Posts |
Posted - 2013-06-19 : 03:55:31
|
Bandi tnx for that additional information..help much appreciated!!! |
|
|
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!
welcomeyep...it has IF ELSE statement but its not necessary here as showed by the other solutions------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
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 |
|
|
|
|
|