I have two columns in DB: StartDate (datetime column) and StartTime (nvarchar column).
StartDate contains date when event shoud start.
StartTime contains time when event should start. It is 24hour format (for example, 22:00 or 12:00).
I need to combine StartDate with StarTime to use it in WHERE clause and compare the result with variable. It would look like:
WHERE COMBINED_STARTDATE_WITH_STARTIME >= @DATETIME_VARIABLE
I am using SQL SERVER 2008.
This is existing DB design and would not like to change it. Probably, I can create third column and combine datetime + startdate into one column, but I am looking for another sollutions (that doesn’t touch database).
You can use something like this:
SQL Fiddle with DateTime Conversion
In the event the start time is
nullthen you can useIsNull()around the value:See SQL Fiddle with Demo
Of course if you are using SQL Server 2008+ you can just cast your value as time:
See SQL Fiddle with Demo