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.
| Author |
Topic |
|
jonasalbert20
Constraint Violating Yak Guru
300 Posts |
Posted - 2005-02-06 : 20:28:26
|
| Good day i have this data...Select dateTrans, ItemCode, QTY from tblALCdateTrans------ItemCode-----QTY02/01/2005 ... 11111111-----102/01/2005 ... 11111111-----202/01/2005 ... 11111112-----102/02/2005 ... 11111112-----102/02/2005 ... 11111111-----202/03/2005 ... 11111112-----502/03/2005 ... 11111112-----102/03/2005 ... 11111111-----202/04/2005 ... 11111112-----202/04/2005 ... 11111112-----102/04/2005 ... 11111111-----302/04/2005 ... 11111111-----102/04/2005 ... 11111111-----102/05/2005 ... 11111111-----1002/05/2005 ... 11111112-----502/06/2005 ... 11111111-----502/06/2005 ... 11111112-----5I want to show with this output...ItemCode---02/01/2005--02/02/2005--02/03/2005--02/04/2005--02/05/2005--02/06/2005_________________________________________________________________________________11111111--- 3 2 2 5 10 511111112--- 1 1 6 3 5 5I want to sum up the qty per dates in a column.HOW?Want Philippines to become 1st World COuntry? Go for World War 3... |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-02-06 : 20:33:32
|
| select[20050201] = (select sum(qty) from tbl t2 where dateTrans = '20050201' and t2.ItemCode = t.ItemCode) ,[20050202] = (select sum(qty) from tbl t2 where dateTrans = '20050202' and t2.ItemCode = t.ItemCode) ,[20050203] = (select sum(qty) from tbl t2 where dateTrans = '20050203' and t2.ItemCode = t.ItemCode) ,[20050204] = (select sum(qty) from tbl t2 where dateTrans = '20050204' and t2.ItemCode = t.ItemCode) ,[20050205] = (select sum(qty) from tbl t2 where dateTrans = '20050205' and t2.ItemCode = t.ItemCode) ,[20050206] = (select sum(qty) from tbl t2 where dateTrans = '20050206' and t2.ItemCode = t.ItemCode)from tbl tgroup by ItemCodeorder by ItemCode==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
jonasalbert20
Constraint Violating Yak Guru
300 Posts |
Posted - 2005-02-06 : 20:59:56
|
| tnx nr supposed i will used that in SP with parameter of this...exec sp_Show from, toHow?Want Philippines to become 1st World COuntry? Go for World War 3... |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-02-06 : 23:06:22
|
| Then as you don't have a fixed number of columns or column names then you will need to use dynamic sql.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|