how we can count records as a group of days like sum of
records for(four mondays),(four tuesday)........ in a month.
group the column for weekdays.

Answer Posted / harshad lakkad (bapunagar) par

--First Create This Function To Return a week Days For
Particular Date--

CREATE FUNCTION [dbo].[udf_DayOfWeek]
(@dtDate DATETIME)
RETURNS VARCHAR(10)
AS
BEGIN
DECLARE @rtDayofWeek VARCHAR(10)
SELECT @rtDayofWeek = CASE DATEPART(weekday,@dtDate)
WHEN 1 THEN 'Sunday'
WHEN 2 THEN 'Monday'
WHEN 3 THEN 'Tuesday'
WHEN 4 THEN 'Wednesday'
WHEN 5 THEN 'Thursday'
WHEN 6 THEN 'Friday'
WHEN 7 THEN 'Saturday'
END
RETURN (@rtDayofWeek)
END

--Now Use this Function As Below
SELECT
Sum(Bank.Amount),
dbo.udf_DayOfWeek(Bank.Date) AS DayOfWeek
From Bank
Group By Bank.Date
-- Here Bank.Amount And Bank.Date Are Column Name Of Bank
Table

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What changes in the front end code is needed if mirroring is implemented for the high availability? : sql server database administration

604


Explain multiserver query

553


Explain for xml explicit mode?

560


Can a stored procedure call itself or a recursive stored procedure? How many levels of sp nesting is possible?

577


What is a result set object returned by odbc_exec()?

546






How can I check if a view exists in a sql server database?

561


what is isolation level at dead lock?

1748


What are dml triggers and types of dml triggers?

547


What are the different types of backups avaialabe in sql server 2005?

620


What is 2nf example?

550


What is the difference between a function and a trigger?

571


Explain the cursor lock types?

551


What are the steps to insert a table?

539


What is star, snowflake and star flake schema? : sql server analysis services, ssas

653


What are parameterized reports?

160