Perform Search between dates. Sql Server

1

Good afternoon,

I'm doing a simple query of a logical in db2 that is numeric but contains dates of the following format 20170831, but when doing the query with both 'between' with the operators '> = < =' brings all the existing dates.

The query is the following

SELECT NROP55, TIPL55, PBAE55, STAT1B, FIPL55 from 
IVRDB2.S103V5HM.xxxx.xxxx 
WHERE Fecha >=  20170801 AND Fecha <= 20170829 
ORDER BY FIPL55 desc

The format is year, month, day and the result is always from 2014 or beyond.

Could you help me?

(I already use the quotes for the dates but it still yields the same result) Greetings

    
asked by Hans 31.08.2017 в 21:09
source

3 answers

2

You need to use the single quotes in your search:

SELECT NROP55, TIPL55, PBAE55, STAT1B, FIPL55 
FROM IVRDB2.S103V5HM.xxxx.xxxx 
WHERE Fecha >=  '20170801' AND Fecha <= '20170829' 
ORDER BY FIPL55 desc**
    
answered by 31.08.2017 / 21:11
source
1

If the date column is of type char (I want to assume that), you could use formats in the dates, such as:

SELECT NROP55, TIPL55, PBAE55, STAT1B, FIPL55 <br>
From IVRDB2.S103V5HM.xxxx.xxxx 
WHERE Convert(char(10),Fecha,121) Between '2017-08-01' AND '2017-08-29' 
ORDER BY FIPL55 desc
    
answered by 31.08.2017 в 23:46
0

If the date column is a numeric type you could try this query to see if it is what you are looking for.

SELECT NROP55, TIPL55,PBAE55,STAT1B,FIPL55,
FROM IVRDB2.S103v5HM.xxxx.xxxx
WHERE Fecha BETWEEN 20170801 AND 20170829
ORDER BY FIPL55 DESC

I hope it serves you, greetings.

    
answered by 31.10.2017 в 14:17