The ugly solution is to strip both dates of their time section (as described above), and then compare if the results are equal.
The better solution is to use the DATEDIFF function, with the DAY or D parameter, and make sure if the result is 0:
Getting Weekday Number Regardless of Database Settings
Use this to have Monday as 0, Tuesday as 1, and so on:
Use this to have Sunday as 0, Monday as 1, and so on. This is in correspondance with C# DayOfWeek Enum:
However the leading spaces are taken into account:
Ammend query rsults with 0 counts for all possible items
Assuming DS as the data-source, we want the count for all items for all persons to be returned. If an item is missing for a person in DS it should be returned with the value of 0. This is how to do it, and it’s inspired from here:
Note that constant tables are comming first in the join-chain, and DS is comming last. Also note that the last join condition binding DS with constant tables must have conditions for all constant tables (here P and T).
DECLARE@myVarvarchar(MAX)DECLAREmy_cursorCURSORFORSELECT*FROMmyTableOPENmy_cursorFETCHNEXTFROMmy_cursorINTO@myVarWHILE@@FETCH_STATUS=0BEGIN-- Do something with @myVarFETCHNEXTFROMmy_cursorINTO@myVarENDCLOSEmy_cursorDEALLOCATEmy_cursor
Kill all connections to a SQL Server Database
Run the first statement and immediately after that the second one to revert the effect of the first statement: