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
 SQL Server Development (2000)
 How Show Horizontal Rows as Vertical Rows

Author  Topic 

CLages
Posting Yak Master

116 Posts

Posted - 2005-11-25 : 06:17:20
Hi
I have a tabela Like this

Dep Code Qty
001 123 12
001 144 08

002 123 50
002 126 10
002 144 30

003 123 44
003 ABC 12

I would like to get like this

dep001 dep002 dep003
Code Qty Qty Qty Balance
123 12 50 44 106
126 0 10 0 10
144 8 30 0 38
abc 0 0 12 12

any help will be Apreciated
Tks in Advance once more
CLages

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-25 : 06:30:21
Do you mean Cross Tab?
http://weblogs.sqlteam.com/jeffs/archive/2005/05.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

CLages
Posting Yak Master

116 Posts

Posted - 2005-11-25 : 06:38:48
Yes, i found some good ideias here
i choose this one
is there a better solution?
Tks
Anyway
Clages




select P.pro_codigo,
P.pro_desc ,
P.pro_grupo,
sum(case when P.pro_deposito = '001' then pro_saldo_fis1 else 0 end),
sum(case when P.pro_deposito = '002' then pro_saldo_fis1 else 0 end)

from produto p
where P.pro_deposito = '001' or
P.pro_deposito = '002'
group by
P.pro_codigo,
P.pro_desc ,
P.pro_grupo
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-25 : 08:31:08
Yes. Test it with large data and see the performance.
Where do you want to show those data?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

CLages
Posting Yak Master

116 Posts

Posted - 2005-11-25 : 09:28:49
This will be a SP called by Crystal Report
For while is running OK
tks
C.Lages
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-25 : 09:30:09
Well
I think Crystal Reports supports Cross Tab
If possible try that also

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -