views:

29

answers:

1

Need to get a certain subgroup of data per day (Separated by weekday)

For example

Select weekday,bla,blabla,blablabla from dbo.blabla
where bla = @StartDate
and bla <=@endDate

I need the output to be:

Monday bla blabla blablabla

Tuesday bla blabla blablabla

If someone could help me that would be awesome.

Thanks & Regards Jacques

A: 

Try to use DATENAME with DW

Something like

SELECT DATENAME(DW, GETDATE())

You can then try something like

DECLARE @Table TABLE(
        VAL FLOAT,
        DateVal DATETIME
)

INSERT INTO @Table SELECT 1, '01 Jan 2010'
INSERT INTO @Table SELECT 2, '02 Jan 2010'
INSERT INTO @Table SELECT 3, '03 Jan 2010'
INSERT INTO @Table SELECT 4, '08 Jan 2010'
INSERT INTO @Table SELECT 5, '09 Jan 2010'

SELECT  DATENAME(DW,DateVal),
        SUM(VAL)
FROM    @Table
GROUP BY DATENAME(DW,DateVal)
astander
I have a job that runs everyday to insert the values daily it inserts the dates into the table.Here is all the data i need:SELECT tat_dateofsub [Dateofsub],tat_weekday [Weekday],tat_model [Model],tat_reciepts [Receipts],tat_dispatches [Dispatch],tat_onhand [On Hand],tat_wip [WIP],tat_AwTriage [Aw Triage],tat_awParts [AW Parts],tat_Technician [At Tech],tat_scrapped [Scrapped],tat_Buffer [Buffer] FROM report..tatNeed to display this in weekly format seperated by day.Can i use this to do this?GROUP BY DATENAME(DW,DateVal)
Jacques444