I have a huge database in ms sql. I have a date stored into a field of type: VARCHAR2
I have the code, but it can’t compare dates. What I mean? There is an input with a launch date. What I need is to get the launchdate inputs where the launchdate is bigger than a date and smaller than another. The problem is that when I change the year from 2012 to 2013 there are no results. Also when I have dates with 0 (like 01.01.2012) it can’t compire them.
What I have so far is:
edited
Can someone help me to get the correct results?
EDIT1
The date is stored as string in this format: yyyy-mm-dd
In your
WHEREclause you are doing a double conversion unnecessarily and actually comparingVARCHARnotDATETIMETo compare
DATETIMEfollowing is enough.Or you can
CASTEDIT: I think you need to check for
NULLvalues of[t].PA_NAMEas well