简体   繁体   中英

SQL using sysdate

I have updated the value of the SAD_PB_CAS_STATDT field equal to sysdate which is the date today. The problem now is when i query something with that SAD_PB_CAS_STATDT = sysdate , it does not return anything.

see my sql code below:

SELECT EMPLID, ACAD_CAREER, STDNT_CAR_NBR, ADM_APPL_NBR, APPL_PROG_NBR, 
SAD_PB_CAS_STATUS, SAD_PB_CAS_STATDT
FROM PS_SAD_PB_CAS
WHERE SAD_PB_CAS_STATUS IN ('ASG', 'USD') 
AND SAD_PB_CAS_STATDT = sysdate;

I'm guessing it has something to do with the return type of sysdate ? does it return something with date and time? any help would be appreciated for me to be able to pull the query with sysdate in the conditions.

As others have mentioned, always check the documentation (including Stack Overflow) before you post a question. There are several ways to make your query work, but I would recommend the following WHERE clause:

WHERE
    SAD_PB_CAS_STATUS IN ('ASG', 'USD') AND
    SAD_PB_CAS_STATDT >= CURDATE() AND               -- today at midnight
    SAD_PB_CAS_STATDT < CURDATE() + INTERVAL 1 DAY;  -- tomorrow at midnight

The reason why this approach is favored over casting your SAD_PB_CAS_STADT column to a date only, is that the above allows an index to be used on the column, if it exists.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM