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 |
vbuser26
Starting Member
21 Posts |
Posted - 2009-01-19 : 02:41:24
|
Hi Experts,I have 7 rows of 100 value in A_COL, i need to make the value 673 to 7 rows also by adding 0 value in C_COL defend on B_COL missing value below is the sample table. Can anyone help me?A_COL B_COL C_COL D_COL 100 50 21 780100 56 22 780100 62 185 780100 68 184 780100 74 184 780100 80 164 780100 86 20 780673 62 92 368673 68 92 368673 74 92 368673 80 92 368 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-19 : 03:17:35
|
so what should be desired output? all values as 0 for other fields? |
|
|
vbuser26
Starting Member
21 Posts |
Posted - 2009-01-19 : 03:27:58
|
Below should be the outputA_COL B_COL C_COL D_COL 100 50 21 780100 56 22 780100 62 185 780100 68 184 780100 74 184 780100 80 164 780100 86 20 780673 50 0 368673 56 0 368673 62 92 368673 68 92 368673 74 92 368673 80 92 368673 86 0 368Note: no using insert statement pls. ^_^ tnx |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-19 : 09:46:57
|
[code]SELECT tmp.A_COL,tmp.B_COL,COALESCE(t.C_COL,0) AS C_COL,tmp.D_COLFROM (SELECT A_COL,B_COL,D_COLFROM (SELECT DISTINCT A_COL,D_COL FROM Table)aCROSS JOIN(SELECT DISTINCT B_COL FROM Table )b)tmpLEFT JOIN Table tON tmp.A_COL=t.A_COLAND tmp.B_COL=t.B_COL[/code] |
|
|
vbuser26
Starting Member
21 Posts |
Posted - 2009-01-20 : 04:13:00
|
Thank you very much visakh16 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-20 : 09:08:36
|
welcome |
|
|
|
|
|