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 |
|
dainova
Starting Member
31 Posts |
Posted - 2010-01-13 : 02:33:57
|
| Hi, all, bit stuck with small task (for Pros, of course), will appreciate you help. I have:Table X1:MainX ___ FlagXM440 ..... NULLlM450 ..... 1M777 ..... NULLTable D1:Sub ___ Main___ AmTL14 .....M440 ... 22220.00L15 ..... M450 ... 333.00L17 ..... M777 ... 6578.00I need to select like this:L14.....M440....22220M450....M450....333 <=== here is replace L17.....M777....6578i.e: IF Main M450 has X1.Flag = 1 , ..... then select D1.Main, D1.Main, D1.AmT.. else..... select D1.Sub, D1.Main, D1.AmT.I bit new to SQL, I composed something scary with nested, but I feel should be smarter option, I’m on SQL 2000. Somebody directed me to Coalesce, but I’m not sure.Will appreciate if you push me to the right direction.Tx to allDai |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-01-13 : 02:39:47
|
| [code]select case when X1.FlagX = 1 then D1.Main else D1.Sub end AS Sub,D1.Main,D1.Amtfrom X1join D1on D1.Main=X1.MainX[/code] |
 |
|
|
|
|
|
|
|