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 |
|
paull
Yak Posting Veteran
50 Posts |
Posted - 2009-08-12 : 12:29:17
|
| Hi guysI dont really know where to start with this!! I it really a problem of nested ifs and cases but I haven't quite mastered those yet!!!I have an insert/select query that populates a new table from 2 existing tables. This line of code simply checks one table (R) to see if it is blank, if it is then it inserts a "0" else puts in whats in that column...case when r.Q15_dummycoded_Q15_S10 ='' and then 0 else r.Q15_dummycoded_Q15_S10 end As Q15_S10Something has come up which means I have now check the other table (F) first for a "1" in that variable. So what I am trying to achieve isCase When F.Q15_S10 = 1 then F.Q15_S10 ELSEcase when r.Q15_dummycoded_Q15_S10 ='' and then 0 else r.Q15_dummycoded_Q15_S10 end As Q15_S10Which in English says "Check F.Q15_S10 for "1", if there is place a "1" in new table, if not, check R.Q15_dummycoded_Q15_S10 to see if it is blank. If it is blank put in a "0" otherwise put in whatever is in r.Q15_dummycoded_Q15_S10.I really hope that makes sense as I have confused myself trying to get it to work!!!Thanks in advance for any helpP |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-08-12 : 12:42:04
|
[code]CASE WHEN F.Q15_S10 = 1 THEN F.Q15_S10 ELSE CASE WHEN r.Q15_dummycoded_Q15_S10 ='' THEN 0 ELSE r.Q15_dummycoded_Q15_S10 END END AS Q15_S10[/code] No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
paull
Yak Posting Veteran
50 Posts |
Posted - 2009-08-12 : 12:50:42
|
| Thank you Fred! I was nearly there!!! |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-08-12 : 12:52:13
|
welcome  No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|