本文发表在 rolia.net 枫下论坛SQL question:
Please don't use sp, function, trigger or program coding.
Is it possible to use only one SQL statement to achieve the following result?
Of course, please tell if you think One-statement is impossible. (You don't have to give the loop coding).
Thanks.
Sample Table:(dash only put in as space to make look nicer, please ignore dash)
Column 1 is sequencial integer (identity) (similar as Oracle sequence).
Column 2 is varchar with different lens and some are empty (nulls) (let's say empty row).
We don't know how many empty rows we got in between, maybe 0,1, or 40, or more.
----------------------------------------
Col1----------Col2
----------------------
1--------------TDF
2--------------null
3--------------null
4--------------S2
5--------------null
6--------------null
7--------------D666666
8--------------null
9--------------null
10-------------null
11-------------null
.
.
.
Question: Is it possible to use only one SQL statement to update and get result:
(Note: The SQL actually filled nulls in column 2 with its former value.)
----------------------------------------
Col1-------Col2
1--------------TDF
2--------------TDF
3--------------TDF
4--------------S2
5--------------S2
6--------------S2
7--------------D666666
8--------------D666666
9--------------D666666
10-------------D666666
11-------------D666666
.
.
.
Thanks.更多精彩文章及讨论,请光临枫下论坛 rolia.net
Please don't use sp, function, trigger or program coding.
Is it possible to use only one SQL statement to achieve the following result?
Of course, please tell if you think One-statement is impossible. (You don't have to give the loop coding).
Thanks.
Sample Table:(dash only put in as space to make look nicer, please ignore dash)
Column 1 is sequencial integer (identity) (similar as Oracle sequence).
Column 2 is varchar with different lens and some are empty (nulls) (let's say empty row).
We don't know how many empty rows we got in between, maybe 0,1, or 40, or more.
----------------------------------------
Col1----------Col2
----------------------
1--------------TDF
2--------------null
3--------------null
4--------------S2
5--------------null
6--------------null
7--------------D666666
8--------------null
9--------------null
10-------------null
11-------------null
.
.
.
Question: Is it possible to use only one SQL statement to update and get result:
(Note: The SQL actually filled nulls in column 2 with its former value.)
----------------------------------------
Col1-------Col2
1--------------TDF
2--------------TDF
3--------------TDF
4--------------S2
5--------------S2
6--------------S2
7--------------D666666
8--------------D666666
9--------------D666666
10-------------D666666
11-------------D666666
.
.
.
Thanks.更多精彩文章及讨论,请光临枫下论坛 rolia.net