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 |
|
alikazim
Starting Member
1 Post |
Posted - 2004-10-09 : 21:18:26
|
| Hi,I need to display data (items purchased in a month) in a hierarchy like below:2004 10 Dec 05 Nov 03 Jul 022003 07 Nov 04 Aug 03I want to return it in a single query and I'm using TreeView web control to display it on webpage for this tree like structure.Here is the DDL:CREATE TABLE Books( BookID INT, BookName VARCHAR2(50), PurchaseDate DATE);INSERT INTO Books VALUES (1, 'XYZ', '11/10/2004');INSERT INTO Books VALUES (2, 'XYZ', '12/10/2004');...I'm able to return data in following manner:2004 Dec 052004 Nov 032004 Jul 022003 Nov 042003 Aug 03Using this query:SELECT YEAR(PurchaseDate), MONTH(PurchaseDate), COUNT(*)FROM PRPressRmsGROUP BY YEAR(PRPressRmDate), MONTH(PRPressRmDate)But I need to return data in following manner:ID ITEM TOTAL PARENT1 2004 102 Dec 05 13 Nov 03 14 Jul 02 25 2005 07 6 Dec 04 57 Nov 03 5Am I doing the right way? Or do I need to change my approach to this problem?Any help will be highly appriciated.RegardsAli |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-10-10 : 11:44:41
|
well u could use unionselect for year union allselect for months union all...have you looked at rollup, cube or compute by in BOL?Go with the flow & have fun! Else fight the flow |
 |
|
|
imughal
Posting Yak Master
192 Posts |
Posted - 2004-10-11 : 06:38:06
|
| instead using count(*) apply select query. i had used this sort of query. below script will help u out it is much simillar that you are looking.CREATE PROCEDURE sp_qbprocessdateslatest@monthno int,@year varchar(5)AsBeginSET NOCOUNT ONselect caclientsloginid,upload_date as 'Processed Send', noofmonths as 'No. of Months',(select top 1 upload_datefrom fileinfo as Bwhere right(rtrim(filename),3)= 'qbw' or right(rtrim(filename),3)= 'qbb' or right(rtrim(filename),3)= 'qbx' andfilename <> 'NULL' andb.caclientsloginid=c.caclientsloginid and b.upload_date < c.upload_date andmonth(b.upload_date) = month(c.upload_date) andyear(b.upload_date) = year(c.upload_date)order by upload_date desc) as 'Un-Processed'from backpdfinfo as c where filename <> 'NULL' andright(rtrim(filename),3)= 'qbw' or right(rtrim(filename),3)= 'qbb' or right(rtrim(filename),3)= 'qbx' andmonth(upload_date) = @monthno andyear(upload_date) = @year order by caclientsloginidend GO |
 |
|
|
|
|
|
|
|