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)
 Table with day-number and count

Author  Topic 

sickhead
Starting Member

5 Posts

Posted - 2002-10-27 : 19:05:44
i need to write a stored procedure to return
a table with all days having a count greater 0.

my table calendar got the following fields

-dte smalldatetime
-desc nvarchar

and so on...

so if there are 5 entries with the dte 20.03.2002 i want the sp to
return 20 and 5 in one row

any ideas?

thx
sickhead

too much of a beautiful thing is wonderful

samrat
Yak Posting Veteran

94 Posts

Posted - 2002-10-27 : 19:31:00
G'dday.

UR query would look somethin like this.

SELECT [Date], CAST(COUNT(*) AS varchar(30)) + ' ' + CAST(DAY([Date]) AS Varchar(30)) AS NewValue
FROM Table1
GROUP BY [Date]

Regards,

Samrat
Go to Top of Page

samrat
Yak Posting Veteran

94 Posts

Posted - 2002-10-27 : 21:46:53
Oops.. shd have read ur question carefully. U want the result set in one for rather then one field

SELECT COUNT(*) AS DayCount, DAY([Date]) AS Daypart
FROM Table1
GROUP BY [Date]

you can run this query in your SP!!

Cheers,


Samrat
Go to Top of Page

sickhead
Starting Member

5 Posts

Posted - 2002-10-28 : 05:50:34
hey Samrat,

thx for the quick answer, worx fine...

cheers
sickhead


too much of a beautiful thing is wonderful
Go to Top of Page
   

- Advertisement -