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)
 SELECT QUERY

Author  Topic 

DENIZ3E
Yak Posting Veteran

56 Posts

Posted - 2005-11-23 : 19:36:21
HI,
I HAVE GOT TWO VIEW. (you know view is slow and my rows>100.000

SELECT TUR='SI',STOK,WEEK,AMOUNT FROM FT_001_SI
SELECT TUR='SA',STOK,WEEK,AMOUNT FROM FT_001_SA

I WANT TO
TUR STOK WEEK1 WEEK2 .... WEEK53
--- ------ ----- ----- -------
SI A SUM(SI_AMOUNT)
SA A SUM(SA_AMOUNT)
FA A SUM(SA_AMOUNT)-SUM(SI_AMOUNT)
DA A (SUM(SA_AMOUNT)-SUM(SI_AMOUNT)) + ("week< week1
sum(SUM(SA_AMOUNT)-SUM(SI_AMOUNT))





rrb
SQLTeam Poet Laureate

1479 Posts

Posted - 2005-11-23 : 20:26:34
Hi Denize

This is called a cross tab query. Search this site for "CrossTab" or read this

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-23 : 23:53:57
or

http://weblogs.sqlteam.com/jeffs/archive/2005/05.aspx

Madhivanan

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

- Advertisement -