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.



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

Answer / 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

More SQL Server Interview Questions

what is difference between Enterprise Manager and Query Analyer

6 Answers   CTS,


How to run queries with sql server management studio express?

0 Answers  


Differences between logshipping and mirroring

1 Answers   Microsoft, Syntel,


What is the difference between Clustered and Non-Clustered Index?

0 Answers  


How to find the second largest salary in the emp database and also How to find 3rd,4th and so on ........ in the emp database plz mail the answer @ mak2786@gmail.com

35 Answers   Oracle, Scend, TechInfini,






What is store procedure?

0 Answers  


How to find 6th highest salary from Employee table ?

10 Answers  


We need to perform what steps in the following order to work with a cursor?

0 Answers  


what is normalization? Explain different levels of normalization? : Sql server database administration

0 Answers  


which table keeps the locking information? : Sql server administration

0 Answers  


What is the default sql server instance name?

0 Answers  


Do you have any idea about the tcl commands?

0 Answers  


Categories