If I have a table that has a column for storing date (name entryDate) ( it’s datatype is datetime) and another column name value (data type is varchar(400)). Right now value column has just Y or N for each row. However, I want to copy all the dates from entryDate column to the value column and i’m okay with the Y or N getting overwritten.
I’m using MS SQL Server 2012. Is the following SQL is what I need to accomplish my task?
I want to do a comparison with the copied value of dates inside the value column with today’s date and if the difference is more than one year, then I want to display a checklist for the user to complete on the front end. If it’s within or less than 1 year from today’s date, then I don’t want to display the checklist to the user. Basically I want to keep showing the checklist if it’s older than one year when they last completed it.
I would suggest to this person that it makes absolutely no sense to do this, especially for the given purpose.
There is a data type for dates for reasons, so you can make queries conditional of the date, which is exaclty what you would use to do what you describe.
So duplicating date data to a non-date format in order to do date comparison defies all logic.
Try it and see what happens. Back up the table first, incase the result is unexpected.
There are infinitely better ways to do it, both from a performance standpoint but from an accuracy standpoint, if you use the tools as they are meant to be used, and not doing some goofy conversions that make no sense whatsoever.