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 |
Jim637
Starting Member
5 Posts |
Posted - 2013-05-23 : 23:19:08
|
Hi guys i have question. Here what i want. I tried to create a sample data. in my sql syntax below I want to see first from table (problem) if i get the value then don't Ago for next table (charge) if i didn't find match from table (problem) then check table(charge) Here is my query Select ID, FNAME, LNAMEFROM TABLE1HERE I WANT TO USE MY CASE STATEMENTCASE WHEN TABLE (PROBLEM) LINK WITH TABLE1 (GET THE VALUE)ELSE WHEN TABLE (CHARGE) LINK WITH TABLE1 (GET THE VALUE)Thank You. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-24 : 00:39:46
|
stub will look like belowSelectID,FNAME,LNAME,COALESCE(p.col,c.col),...FROM TABLE1 t1LEFT JOIN PROBLEM pON conditionLEFT JOIN CHARGE cON condition ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
Jim637
Starting Member
5 Posts |
Posted - 2013-05-25 : 00:21:31
|
Hi Visakh thank you for your reply. Quick question. SelectID,FNAME,LNAME,COALESCE(p.col,c.col), (If I skip this COALESCE,Do you think it should be fine?, I am using Union in 5 queries. So i don't need this)...FROM TABLE1 t1LEFT JOIN PROBLEM pON conditionLEFT JOIN CHARGE cON condition |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-25 : 09:28:38
|
the coalesce is only required if you want value to be retrieved from any of the left join tables, otherwise you can dispense with it------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|
|
|