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

if 3 duplicate records in table,i want to delete 2 alternating duplicate records by keeping 1 duplicate and 1 original as it is,how?

2 Answers  


Difference between: - Delete & Truncate - Table & View - Constraints & Triggers

1 Answers   United Healthcare,


Can we delete data from a view?

0 Answers  


Other than truncate statement, which other command can by-pass the trigger on the tables?

0 Answers  


How are the exceptions handled in sql server programming?

0 Answers  






Explain what are various ways to enhance the ssrs report?

0 Answers  


Explain in brief about Microsoft SQL server?

0 Answers  


1.what is the diff between nolock optimizer and read uncommitted isolation? 2.what is the diff between revoke and deny? 3.what is percieved down time? 4.whether password protection are required for backups?if yes why?if no why? 5.what is fill factor? 6.what is cost analysis? 7.what is mean by piece meal restore? 8.what is 'rowguidcol'? 9.impersonate permission? 10.what is selectivity?

0 Answers  


How make remote connection in database?

1 Answers  


how to avoid cursors? : Sql server database administration

0 Answers  


Magic Tables ?

2 Answers   Thomson Reuters,


What are the disadvantages of using the stored procedures?

0 Answers  


Categories