Here is a method that uses the FLOOR and CAST function to truncate the time portion from a date. Below, is a DATEPART example that once again returns all the records that have a SAMPLE_DATE in ''.SELECT * FROM DATE_SAMPLE WHERE DATEPART(YEAR, SAMPLE_DATE) = '2003' AND DATEPART(MONTH,SAMPLE_DATE) = '04' AND DATEPART(DAY, SAMPLE_DATE) = '09'Using the FLOOR Function:As I have said before there are many ways to accomplish the same thing. With the DATEPART function you can build a WHERE statement that breaks apart each piece (year, month, day) of the SAMPLE_DATE and verifies that each piece is equal to the year, month and day you are looking for. This record would not be returned because when SQL Server converts the string '' to a date/time value it would be equal to the SAMPLE_DATE on record 4.Using the DATEPART Function:Another way to return the records that have a SAMPLE_DATE for a particular date is to use the DATEPART function. If only the greater than sign was used the SELECT statement would not return record 4. Here's what I found while playing around, please let me know if it helps you.SELECT * FROM DATE_SAMPLE WHERE SAMPLE_DATE >= '' AND SAMPLE_DATE =) expression instead of just greater than (>). © 2023 HyperObjc.Okay, we're getting a little out of my league here, but I'll try to help. Have any questions or feature requests? Please feel free to create an issue.
0 Comments
Leave a Reply. |