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 are the requirements to use odbc connections in php scripts?

689


How do you create a clustered index?

611


What are the restrictions that views have to follow?

640


Name 3 of the features that the sql server built-in function loginproperty performs on standard logins? : sql server security

787


What is checkpoint process in the sql server?

638






What is the osql utility?

633


What is RMS migrations?

1786


What is row_number()?

694


What xml support does the sql server extend?

620


What is faster join or union?

710


Working with TLogs

1538


What are the advantages of sql azure?

126


What is the most common type of join?

625


Explain about Views?

679


How to choose all records from the table?

725