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 2005 Forums
 Transact-SQL (2005)
 stored procedure syntax help

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2007-06-04 : 03:11:38
CREATE PROCEDURE [dbo].[getnumberpaidpersite]
@fromdate datetime,
@todate datetime,
@userid int
AS
BEGIN
declare @paid int
-- SET NOCOUNT ON added to prevent extra result sets from

SET NOCOUNT ON;


SELECT count(id) as mycount,usertype from payments where received>=@fromdate and received<=@todate group by usertype

return
END


with the above sp

this returns now

usertype mycount

001 11
002 6

based on the dates

now what i really want is to take bring the count for the week of @fromdate so that it should return

usertype sunday monday tuesday wed thursday friday (only until the @fromdate) (so if @fromdate is monday it will only return sunday and monday)

001 1 3 4 1 1 1
002 1 2 3 0 0 0

can someone help me with this?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-06-04 : 03:53:42
After more than 500 posts, you should know how to search to CROSSTAB / PIVOT queries.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

pootle_flump

1064 Posts

Posted - 2007-06-04 : 04:51:30
http://www.dbforums.com/showthread.php?p=6276233&posted=1#post6276233
Go to Top of Page
   

- Advertisement -