|
Posted by Danny on 07/17/05 17:20
Try something like the following or if there are many individual dates you
could insert them into a table variable.
SELECT customerid
FROM orders
WHERE orderdate IN ('1996/8/23', '1996/8/27')
OR orderdate BETWEEN '1996/9/1' AND DATEADD(DD, -1, '1996/10/1')
DECLARE @OrderLookup TABLE (orderdate DATETIME)
INSERT INTO @orderlookup VALUES ('1996/8/23')
INSERT INTO @orderlookup VALUES ('1996/8/27')
SELECT customerid
FROM orders
WHERE orderdate IN (SELECT orderdate FROM @OrderLookup)
OR orderdate BETWEEN '1996/9/1' AND DATEADD(DD, -1, '1996/10/1')
SELECT customerid
FROM orders
WHERE orderdate IN ('1996/8/23', '1996/8/27')
OR orderdate BETWEEN '1996/9/1' AND DATEADD(DD, -1, '1996/10/1')
"Chris" <computertje2@hotmail.com> wrote in message
news:2ba80$42da3499$52ac4abf$812@news.versatel.nl...
> Hi guys,
>
> I am having some difficulties making a sql-statement.
> I took the Northwind database as an example.
>
> I want to return the customernumbers from the orders-table, where the
> orderdate is 1996/8/23 or 1996/8/27 or the whole month of september.
>
> I came up with the following statement, but this one only returns the
> customers from wich the orderdate is in the whole month of september:
>
> select customerid from orders where orderdate in (#1996/8/23#,
> #1996/8/27#, (select orderdate from orders where orderdate between
> #1996/9/1# and #1996/8/30#))
>
> I know i could do it on another way, something like:
>
> select customerid from orders where orderdate = #1996/8/23# OR orderdate =
> #1996/8/27# OR orderdate between #1996/9/1# and #1996/8/30#
>
> But what if i want to check for 20 diferent dates? Doing like this would
> make the statement very long and unreadable.
>
> Does anyone have a suggestion?
>
> Thanks in advance!
>
>
> Chris
>
>
Navigation:
[Reply to this message]
|