Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 suppress specific column in SQL

Author  Topic 

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2008-09-28 : 09:33:33
Good day everyone...

I have this datas...

tblDetails

select 1 as transid, 111 as codeper, 1 as empid, 1 as itemcode union all
select 2 as transid, 112 as codeper, 2 as empid, 2 as itemcode union all
select 3 as transid, 113 as codeper, 3 as empid, 1 as itemcode union all
select 4 as transid, 111 as codeper, 1 as empid, 1 as itemcode union all
select 5 as transid, 112 as codeper, 2 as empid, 2 as itemcode union all
select 6 as transid, 113 as codeper, 3 as empid, 1 as itemcode union all
select 7 as transid, 111 as codeper, 1 as empid, 1 as itemcode union all
select 8 as transid, 113 as codeper, 3 as empid, 1 as itemcode union all
select 9 as transid, 111 as codeper, 1 as empid, 1 as itemcode


tblHeader

select 1 as itemcode, 5 as qty union all
select 2 as itemcode, 50 as qty


What I want is to join the details and the header however I want to suppress a specific column. On this sample data, I want to suppress the qty column. Order by codeper and transid.

Desired result should look like this.

select 1 as transid, 111 as codeper, 1 as empid, 1 as itemcode, 5 as qty union all
select 4 as transid, 111 as codeper, 1 as empid, 1 as itemcode, 0 as qty union all
select 7 as transid, 111 as codeper, 1 as empid, 1 as itemcode, 0 as qty union all
select 9 as transid, 111 as codeper, 1 as empid, 1 as itemcode, 0 as qty union all
select 2 as transid, 112 as codeper, 2 as empid, 2 as itemcode, 50 as qty union all
select 5 as transid, 112 as codeper, 2 as empid, 2 as itemcode, 0 as qty union all
select 3 as transid, 113 as codeper, 3 as empid, 1 as itemcode, 5 as qty union all
select 6 as transid, 113 as codeper, 3 as empid, 1 as itemcode, 0 as qty union all
select 8 as transid, 113 as codeper, 3 as empid, 1 as itemcode, 0 as qty

Any help would be greatly appreciated. Thank you in advance.




For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-09-28 : 10:34:47
Select tbd.transid,tbd.codeper,tbd.empid
,tbd.itemcode,coalesce(tbh.qty,0)as qty
from tbldetails tbd left join
tblheaders tbh on tbd.itemcode=tbh.itemcode
Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2008-09-28 : 19:39:00
quote:
Originally posted by sodeep

Select tbd.transid,tbd.codeper,tbd.empid
,tbd.itemcode,coalesce(tbh.qty,0)as qty
from tbldetails tbd left join
tblheaders tbh on tbd.itemcode=tbh.itemcode




Thanks for you're reply. However the result set is wrong.







For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-29 : 02:10:56
[code]select d.transid,d.codeper,d.empid,d.itemcode,case when d1.itemcode is not null then h.qty else 0 end
from tblDetails d
inner join tblHeader h
on h.itemcode=d.itemcode
left join (select codeper,itemcode,min(transid) as mintran
from tblDetails
group by codeper,itemcode)d1
on d1.codeper=d.codeper
and d1.itemcode=d.itemcode
and d1.mintran=d.transid
order by codeper,transid[/code]
Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2008-09-29 : 20:36:45
quote:
Originally posted by visakh16

select d.transid,d.codeper,d.empid,d.itemcode,case when d1.itemcode is not null then h.qty else 0 end
from tblDetails d
inner join tblHeader h
on h.itemcode=d.itemcode
left join (select codeper,itemcode,min(transid) as mintran
from tblDetails
group by codeper,itemcode)d1
on d1.codeper=d.codeper
and d1.itemcode=d.itemcode
and d1.mintran=d.transid
order by codeper,transid





thanks a lot.




For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-29 : 23:57:09
quote:
Originally posted by jonasalbert20

quote:
Originally posted by visakh16

select d.transid,d.codeper,d.empid,d.itemcode,case when d1.itemcode is not null then h.qty else 0 end
from tblDetails d
inner join tblHeader h
on h.itemcode=d.itemcode
left join (select codeper,itemcode,min(transid) as mintran
from tblDetails
group by codeper,itemcode)d1
on d1.codeper=d.codeper
and d1.itemcode=d.itemcode
and d1.mintran=d.transid
order by codeper,transid





thanks a lot.




For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...


welcome
Go to Top of Page
   

- Advertisement -