dbTalk Databases Forums  

Query Update - subquery?

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Query Update - subquery? in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
info
 
Posts: n/a

Default Query Update - subquery? - 12-29-2007 , 01:11 AM






Hi,

I have one table name: art

column:

symbol_art price1 price2
----------- ------- -------
AG-0001 20 40
AG-0001S null null
AG-0002 40 60
AG-0002S null null
....
How paste in null price1 and price2 from oryginal symbol_art AG-0001,AG-0002 ?
(duplicate symbol_art %-%'S ' it's always the same for oryginal symbol_art)

thanks for any help
Tom







Reply With Quote
  #2  
Old   
Madhivanan
 
Posts: n/a

Default Re: Query Update - subquery? - 12-29-2007 , 02:52 AM






On Dec 29, 12:11*pm, "info" <informatyk@fitness[CUT]authority.pl>
wrote:
Quote:
Hi,

I have one table name: art

column:

symbol_art * * * * *price1 * *price2
----------- * * * * *------- * -------
AG-0001 * * * * * 20 * * * * *40
AG-0001S * * * * null * * * *null
AG-0002 * * * * * 40 * * * * *60
AG-0002S * * * * null * * * *null
...
How paste in null price1 and price2 from oryginal symbol_art AG-0001,AG-0002 ?
(duplicate symbol_art *%-%'S ' *it's always the same for oryginal symbol_art)

thanks for any help
Tom

declare @t table(symbol_art varchar(100), price1 int,price2 int)
insert into @t
select 'AG-0001', 20, 40 union all
select 'AG-0001S', null, null union all
select 'AG-0002', 40 , 60 union all
select 'AG-0002S', null , null


update t1
set price1=t2.price1,
price2=t2.price2
from @t t1 inner join
(
select symbol_art,price1,price2 from @t where price1 is not null and
price2 is not null
) as t2
on t1.symbol_art like t2.symbol_art+'%'
where t1.price1 is null and t1.price2 is null

select * from @t




Reply With Quote
  #3  
Old   
Roy Harvey (SQL Server MVP)
 
Posts: n/a

Default Re: Query Update - subquery? - 12-29-2007 , 05:56 AM



On Sat, 29 Dec 2007 08:11:55 +0100, "info"
<informatyk@fitness[CUT]authority.pl> wrote:

Quote:
Hi,

I have one table name: art

column:

symbol_art price1 price2
----------- ------- -------
AG-0001 20 40
AG-0001S null null
AG-0002 40 60
AG-0002S null null
...
How paste in null price1 and price2 from oryginal symbol_art AG-0001,AG-0002 ?
(duplicate symbol_art %-%'S ' it's always the same for oryginal symbol_art)

thanks for any help
Tom
As a side note, it should be understood that the way the symbol_art
column is being used it should have been two columns. The sort of
complications that result from not using two columns require a
complicated query. With two columns it would have been simple and
obvious.

Roy Harvey
Beacon Falls, CT


Reply With Quote
  #4  
Old   
--CELKO--
 
Posts: n/a

Default Re: Query Update - subquery? - 01-02-2008 , 03:19 PM



Quote:
How paste in null price1 and price2 from original symbol_art AG-0001,AG-0002 ? (duplicate symbol_art %-%'S ' it's always the same for original symbol_art)
Why don't you create a VIEW with the long and short art_symbols in
it? It will always be right, not require storage, save constant
updating, etc.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.