PPP123
Дата: 08.09.2006 13:52:30
Raznitsa vtom chto V etom tablitse netu kolonki ID
V tom primere videlenie proisxodit po kolonki ID i etat skript ne rabotaet ID vsegda ravna 0 2
declare @PRICE table(Tovar varchar(10) identity, Postav. varchar(20) identity, Tsena money)
insert into @PRICE
select 'TV-1','Pavel',12.00
union select 'TV_1','Dlia Vsex',14.00
union select 'TV_2','Nikita',15.00
union select 'TV_2','Dlia Vsex',17.00
Александр Волок (def1983)
Дата: 08.09.2006 13:56:53
Не забывайте о скриптах для создания данных!
create table #tovar (tv_id varchar(10), postav varchar(50), price money)
insert into #tovar values ('tv-1', 'pavel', 12)
insert into #tovar values ('tv-1', 'dlya_vseh', 14)
insert into #tovar values ('tv-2', 'nikita', 15)
insert into #tovar values ('tv-2', 'dlya_vseh', 17)
declare @postav varchar(50)
set @postav = 'pavel'
select tv_id, price from #tovar where postav = @postav
union
select tv_id, price from #tovar where postav = 'dlya_vseh'
and tv_id not in (select tv_id from #tovar where postav = @postav)
drop table #tovar
Барбудас
Дата: 08.09.2006 14:50:25
ну и тогда - предлагаю просто как вариант (без объединения)
declare @venvor varchar(20)
select @venvor='Nikita'
-- Это типа параметр
declare @PRICE table(tovar varchar(10), venvor varchar(20), price money)
insert into @PRICE
select 'TV_1','Pavel',12.00
union select 'TV_1','Dlia Vsex',14.00
union select 'TV_2','Nikita',15.00
union select 'TV_2','Dlia Vsex',17.00
-- таблица; уж извините, но убрал identity из колонок :)))
-- Запрос:
select tovar, cast(substring (
min(case venvor
when @venvor then '0'
when 'Dlia Vsex' then '1'
else '2'
end+' '+cast(price as varchar(30)))
,3,30) as money) as 'price'
from @PRICE
group by tovar
PPP123
Дата: 08.09.2006 17:15:29
I eta rabotaet xarasho
create table #tovarPrice (tv_id varchar(10), tv_LotNo varchar(10), tv_SerialNo varchar(10), postav varchar(50), price money)
insert into #tovarPrice values ('tv-1','','', 'pavel', 12)
insert into #tovarPrice values ('tv-1','Lot1','', 'pavel', 13)
insert into #tovarPrice values ('tv-1','','', 'dlya_vseh', 14)
insert into #tovarPrice values ('tv-1','Lot1','', 'dlya_vseh', 18)
insert into #tovarPrice values ('tv-2','','', 'nikita', 15)
insert into #tovarPrice values ('tv-2','','', 'dlya_vseh', 17)
create table #tovarList (tv_id varchar(10), tv_LotNo varchar(10), tv_SerialNo varchar(10), postav varchar(50))
insert into #tovarList values ('tv-1','','', 'pavel')
insert into #tovarListvalues ('tv-1','Lot12','', 'pavel')
insert into #tovarList values ('tv-1','','', 'dlya_vseh')
insert into #tovarList values ('tv-1','Lot1','', 'dlya_vseh')
insert into #tovarListvalues ('tv-2','','', 'nikita', 15)
insert into #tovarList values ('tv-2','','', 'dlya_vseh')
Mojna li Obedinits Eti tablitsi tak chto Kajdaia tsena tavar+Lot+Serial tsene V #tovarPrice esli net tagda brats tsenu 'dlya_vseh' pustimi tavar+Lot+Serial
S uvajeniam