I have a table in my database in which one of the columns is stored in joining_months string format Such as January, February, March .... (and so on).
Now I want to run an SQL query in this table to get those lines, which is specified before or after specified in a month
something Like this:
Select from table 1 * where join_month & gt; Or & lt; 'March' How do I compare the months stored in string format?
Please help!
Instead of doing so, I found out how to exclude it:
Another way to do this is: SELECT CHARINDEX (month name, 'XXJenfbberMRAAMJJULUUGSOPOTNVDC') / 3 AS Month Number
You remove it from the first 3 letters of your month and hard-coded string 'XXJANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC Can modify it by comparing it. Should do this.
Your query might be something like this:
select CHARINDEX (substing_month, 1,3), 'XXJANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC') / 3 AS Monthnumber, * from table 1 Monthnumber & gt; Or & lt; 3
Comments
Post a Comment