I need a help in getting the output.
I want to display the values of T5 to 1,T3 to 2,T1 to 5.When the count is > then 1 it should be 4.
declare @Prod1 table
(
Csid bigint,
sid bigint
)
insert into @Prod1
select 4103, 101 union all
select 4101, 195 union all
select 4103, 101 Union all
select 4104, 201 Union all
select 4105, 202
declare @Prod2 table
(
sid int,
Prod2 char(2)
)
insert into @Prod2
select 101, 'T1' union all
select 101, 'T2' union all
select 195, 'T5' Union all
Select 201, 'T3' Union all
Select 202, 'T1'
select p1.Csid, p1.sid,
prod2 = case when count(*) > 1 then '4' else max(p2.Prod2) end
from @Prod1 p1 inner join @Prod2 p2
on p1.sid = p2.sid
group by p1.Csid, p1.sid
Output:
Csid sid prod2
-------------------- -------------------- -----
4103 101 4
4101 195 1
4104 201 2
4105 202 5
thanks for yr help in advance!
I want to display the values of T5 to 1,T3 to 2,T1 to 5.When the count is > then 1 it should be 4.
declare @Prod1 table
(
Csid bigint,
sid bigint
)
insert into @Prod1
select 4103, 101 union all
select 4101, 195 union all
select 4103, 101 Union all
select 4104, 201 Union all
select 4105, 202
declare @Prod2 table
(
sid int,
Prod2 char(2)
)
insert into @Prod2
select 101, 'T1' union all
select 101, 'T2' union all
select 195, 'T5' Union all
Select 201, 'T3' Union all
Select 202, 'T1'
select p1.Csid, p1.sid,
prod2 = case when count(*) > 1 then '4' else max(p2.Prod2) end
from @Prod1 p1 inner join @Prod2 p2
on p1.sid = p2.sid
group by p1.Csid, p1.sid
Output:
Csid sid prod2
-------------------- -------------------- -----
4103 101 4
4101 195 1
4104 201 2
4105 202 5
thanks for yr help in advance!