Dan Paschevici
Dan Paschevici

Reputation: 1021

MS SQL - 2 different range of date

I use MS SQL, and I have in my table 2 columns. DATE and VALUE, and I want to select that in one column to display values between 2 dates and in second column to display value with different range of dates.something like:

SELECT value1, value2 
FROM TABLE 
WHERE (value1 = date between '2015-05-10' and '2015-09-10')
and (value2 = date between '2015-04-10' and '2015-11-01'). 

All I want is that from the same column with date extract values with different range of dates. Thank you!

Upvotes: 1

Views: 97

Answers (3)

Nguyễn Hải Triều
Nguyễn Hải Triều

Reputation: 1464

You can try this:

SELECT A.DATE, A.VALUE1, A.VALUE2
FROM (
   SELECT
      DATE,
      VALUE AS VALUE1
   FROM TABLE
   WHERE DATE BETWEEN'2015-05-10' AND '2015-09-10'
   ) AS A
FULL OUTER JOIN (
   SELECT
      DATE,
      VALUE AS VALUE1
   FROM TABLE
   WHERE DATE BETWEEN'2015-04-10' AND '2015-11-01'
   ) AS B
   ON A.DATE = B.DATE

Upvotes: 0

Devart
Devart

Reputation: 121952

a bit unclear for me... you mean something like this -

SELECT value1, value2 
FROM tbl
WHERE value1 BETWEEN '2015-05-10' AND '2015-09-10'
    AND value2 BETWEEN '2015-04-10' AND '2015-11-01'

Upvotes: 2

singhswat
singhswat

Reputation: 906

Updated based on your response... Since you are using different date values, you can extend the query!

 SELECT value1, value2 
FROM TABLE
WHERE (value1 >= date1 and date2 <=value1 )
AND  (value2 >= date3 and date4 <=value2 )

Upvotes: 1

Related Questions