开发者

Procedure returning multiple values

I have a database which maintains interactions with my application, a log kinds.

I want to generate reports for total interactions per day in a month. What is th开发者_如何转开发e best possible way to write a procedure that would return up 30 values, each value representing the count for a day?

I am using SQL Server 2005. I retrieve these values in a .NET code, upon which I want to run my algorithm.

Thanks.


Your sql query will look like the following.

select top 30 DATEPART(day, InteractionDate) as Day, COUNT(1) as Interactions from logTable group by DATEPART(day, InteractionDate)

In .NET you can use SqlDataReader and store values in a List


Stored procedures often return result sets - what you want here is a simple SELECT statement in your stored procedure. Depending on what technology you are using, you can use a SqlDataReader to get data back into your own structures or SqlDataAdapter to grab it all into a DataSet object.

So we've broken it down into two tasks: (1) Write a SELECT to produce the data you want, (2) Use a DR/DA in the app/service to retrieve it.

evpo gives a good example of the first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜