I want to query the database within a stored procedure with the following SQL statement:
SELECT date1 FROM table INTO dates
WHERE date1 < CONVERT(VARCHAR(8), GETDATE(), 112)
AND date1 > CONVERT(VARCHAR(8), DATEADD(DAY, -4, GETDATE()), 112);
I get an error on the WHERE clause, what am I doing incorrectly?
Assuming date1 is datetime type then Use Between
SELECT date1 INTO dates FROM table
WHERE date1 BETWEEN CONVERT(VARCHAR(8), DATEADD(DAY, -4, GETDATE()), 112) AND
CONVERT(VARCHAR(8), GETDATE(), 112);
if date1 is not datetime, then convert it to then Use Between
SELECT date1 INTO dates FROM table
WHERE CONVERT(VARCHAR(8), date1, 112) BETWEEN CONVERT(VARCHAR(8), DATEADD(DAY, -4, GETDATE()), 112) AND
CONVERT(VARCHAR(8), GETDATE(), 112);
The syntax erro is because the INTO
is wrong.
1) But as @Jonathan has mentioned , the funcitions GETDAT, CONVERT, DATEADD aren't native and not exists at INFORMIX database. Unless you have create it...
2) The "dates" should be a variable at your SPL.
3) The SELECT should return only 1 row....
SELECT date1 INTO dates FROM table
WHERE date1 < CONVERT(VARCHAR(8), GETDATE(), 112)
AND date1 > CONVERT(VARCHAR(8), DATEADD(DAY, -4, GETDATE()), 112);
This should be a valid Informix syntax:
SELECT date1 INTO dates FROM table
WHERE date1 < today
AND date1 > today - 4 units day ;
For more information about the syntax , please check at the IBM Knowledge Center
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.