Help with SQL query
Posted
by user154301
on Stack Overflow
See other posts from Stack Overflow
or by user154301
Published on 2010-05-12T08:41:36Z
Indexed on
2010/05/12
8:44 UTC
Read the original article
Hit count: 167
Hello,
I have list of DateTime values, and for each value I need to fetch something from the database. I would like to do this with one query. I know it's possible to pass a table (list) to the stored procedure, but Im not sure how to write the query itself.
Let's say I have the following table:
CREATE TABLE Shows(
ShowId [int] NOT NULL,
StartTime DateTime NOT NULL,
EndTime DateTime NOT NULL
)
and an array of dates
DECLARE @myDateArray MyCustomDateArrayType
Now, if I were fetching a single item, I would write a query like this:
SELECT * FROM Shows
WHERE StartTime > @ArrayItem and @ArrayItem < EndTime
where @ArrayItem is an item from @myDateArray .
But how do I formulate the query that would fetch the information for all array items?
Thanks!
© Stack Overflow or respective owner