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 happens if ntwdblib.dll is missing on your machine?

0 Answers  


What are the advantages of user defined function?

0 Answers  


Explain filtered indexes?

0 Answers  


You are doing log shipping due to some reasons it is failing. How you will proceed from there

0 Answers  


What is default constraint in ms sql server?

0 Answers  






What is a mutating table error and how can you get around it?

0 Answers  


Do you know what is a linked server in sql server?

0 Answers  


What is faster join or union?

0 Answers  


What are the different ways of moving data/databases between servers and databases in SQL Server?

1 Answers  


How to list all tables in the database using odbc_tables()?

0 Answers  


What are the various Operating system files that every SQL server 2005 database has and what is the purpose.

0 Answers   Microsoft,


can foreign key take role of primary key?

5 Answers   CarrizalSoft Technologies, TCS, Villa Marie,


Categories