|
Home > Archive > ASE Database forum > December 2005 > How to insert to T1 from T2 like this
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to insert to T1 from T2 like this
|
|
| Albert 2005-12-09, 8:25 pm |
| Hello, Sybase experts,
I have another question :
There are 2 tables T1 and T2,
T1
(NO, C1, C2, C3)
T2
(NO, TYPE, VALUE)
NO TYPE VALUE
------------------
1 C1 aaa
1 C2 bbb
1 C3 ccc
2 C1 xxx
2 C2 yyy
2 C3 zzz
.....
I want to insert to T1 from T2, and let T1 get data like this:
T1
NO C1 C2 C3
--------------------
1 aaa bbb ccc
2 xxx yyy zzz
.......
How can I use one insert statement, or one update statement do that ?
Thank you very much.
Albert
---== Posted via the PFCGuide Web Newsreader ==---
http://www.mcse.ms/_newsgroups/group_list.asp
| |
|
| Maybe something like
insert t1
select c1
, max(case when c2 = 'C1' then c3 else null end)
, max(case when c2 = 'C2' then c3 else null end)
, max(case when c2 = 'C3' then c3 else null end)
from t2
group by c1
> Hello, Sybase experts,
>
> I have another question :
>
> There are 2 tables T1 and T2,
> T1
> (NO, C1, C2, C3)
>
> T2
> (NO, TYPE, VALUE)
> NO TYPE VALUE
> ------------------
> 1 C1 aaa
> 1 C2 bbb
> 1 C3 ccc
> 2 C1 xxx
> 2 C2 yyy
> 2 C3 zzz
> ....
>
> I want to insert to T1 from T2, and let T1 get data like
> this: T1
> NO C1 C2 C3
> --------------------
> 1 aaa bbb ccc
> 2 xxx yyy zzz
> ......
>
> How can I use one insert statement, or one update
> statement do that ?
>
> Thank you very much.
>
> Albert
>
>
>
> ---== Posted via the PFCGuide Web Newsreader ==---
> http://www.mcse.ms/_newsgroups/group_list.asp
|
|
|
|
|