Re: UPDATE - UNION
From: Vinod Kumar (vinodk_sct_at_NO_SPAM_hotmail.com)
Date: 02/14/05
- Next message: Vinod Kumar: "Re: Back Up"
- Previous message: Jacco Schalkwijk: "Re: Back Up"
- In reply to: Bob: "Re: UPDATE - UNION"
- Next in thread: Babu M.K: "Re: UPDATE - UNION"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 14 Feb 2005 16:31:12 +0530
Here is my shot at the problem. I am still not clear but will give it my
shot ... You can change the query as:
SELECT id,col1 as MyAlias, 'Col1' as TargetCol FROM TABLE1
UNION ALL
SELECT id,col2 as MyAlias, 'Col2' as TargetCol FROM TABLE1
UNION ALL
SELECT id,col3 as MyAlias, 'Col3' as TargetCol FROM TABLE1
This way you know which is tha column data we are getting. And during the
update do it:
Update Table1
SET Col1 = CASE WHEN TargetCol = 'Col1' THEN <<Updated Value>> END,
Col2 = CASE WHEN TargetCol = 'Col2' THEN <<Updated Value>> END,
Col3 = CASE WHEN TargetCol = 'Col3' THEN <<Updated Value>> END
from #<OurTransposedTable>
PS: I am still not sure to how you update. Can you post the complete repro.
-- HTH, Vinod Kumar MCSE, DBA, MCAD, MCSD http://www.extremeexperts.com Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp "Bob" <Bob@discussions.microsoft.com> wrote in message news:66BC7A32-59E9-468A-97B4-005A1992585E@microsoft.com... > I am using SQL SERVER 2000 and transact-sql > > description: > my table > TABLE1 (id,col1,Col2,col3) > -> id = primary key > my query > SELECT id,col1 as MyAlias FROM TABLE1 > UNION ALL > SELECT id,col2 as MyAlias FROM TABLE1 > UNION ALL > SELECT id,col3 as MyAlias FROM TABLE1 > > With this query, I can only update rows of the first query(SELECT id,col1 as > MyAlias FROM TABLE1) > > > I'm not english so I'm not sure that my post gives you answers you need. > > Thanks for your response > > > "Vinod Kumar" wrote: > > > Can you give us more information on what your requirement is. If you can > > post us the DDL and DML's with sample output it would be nice. > > > > Just a distant shot, if you are using something with a view then you can > > take a look at INSTEAD OF triggers from BOL. > > > > -- > > HTH, > > Vinod Kumar > > MCSE, DBA, MCAD, MCSD > > http://www.extremeexperts.com > > > > Books Online for SQL Server SP3 at > > http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp > > > > "Bob" <Bob@discussions.microsoft.com> wrote in message > > news:3024D47A-C0C6-42BC-83DF-9CA377AFD495@microsoft.com... > > > I made a query which uses 4 columns of the same table and displays it in 4 > > rows > > > > > > ex : SELECT XX as Col1 FROM TABLE1 > > > UNION ALL > > > SELECT YY as Col1 FROM TABLE1 > > > ..... > > > I want these rows to be updatable but, I just can update rows of the first > > > query. > > > > > > How can I resolve this problem. > > > > > >
- Next message: Vinod Kumar: "Re: Back Up"
- Previous message: Jacco Schalkwijk: "Re: Back Up"
- In reply to: Bob: "Re: UPDATE - UNION"
- Next in thread: Babu M.K: "Re: UPDATE - UNION"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|