The best way to post your table structure is as a CREATE TABLE statement,
including keys and constraints. For the moment I'll assume that your table
looks like this:
CREATE TABLE TimeClass (id INTEGER NOT NULL, name VARCHAR(20) NOT NULL,
fromtime DATETIME NOT NULL, totime DATETIME NOT NULL, date DATETIME NULL /*
??? PRIMARY KEY NOT SPECIFIED */)
In this case the query you want could be:
SELECT id
FROM TimeClass
WHERE (@dt >= date AND @dt < DATEADD(DAY,1,date))
OR (@dt >= fromtime AND @dt < totime)
But possibly your problem is due to you storing dates and times separately
(I'm guessing that based on your column names). That's not a design I would
recommend but if you post the table structure and some sample data too then
maybe we can understand your requirements better.
This article explains what information to post to stand the best chance of
getting help with your problem:
http://www.aspfaq.com/etiquette.asp?id=5006 Hope this helps.
--
David Portas
SQL Server MVP