0

I would like to know if it is possible change the data in SQL temporarily

I have three months as varchar July, August, and September. I would like to change them to 1, 2, and 3 respectively so that I can do the following:

SELECT * FROM
(
(SELECT aID, month AS monthA FROM tblA) AS a
INNER JOIN
(SELECT bID, month AS monthB FROM tblB) AS b
ON a.ID = b.ID
)
WHERE a.month < b.month

I know this works

SELECT * FROM
    (
    (SELECT aID, month AS monthA FROM tblA) AS a
    INNER JOIN
    (SELECT bID, month AS monthB FROM tblB) AS b
    ON a.ID = b.ID
    )
    WHERE (a.month = 'July' AND b.month = 'August')
user3772063
  • 39
  • 2
  • 7

1 Answers1

0

It sounds like you'd just like to just stage the varchar data as 1,2,3 and not necessarily change it in the Database is that correct?

Why don't you do a case stmt to change the values to 1,2,3 and then do what you need to.

 SELECT * FROM
(
(SELECT aID, CASE month WHEN 'July' THEN '1' WHEN 'August' THEN '2' WHEN 'September' THEN '3' ELSE month END AS monthA FROM tblA) AS a
INNER JOIN
(SELECT bID, CASE month WHEN 'July' THEN '1' WHEN 'August' THEN '2' WHEN 'September' THEN '3' ELSE month END AS monthB FROM tblB) AS b
ON a.aID = b.bID
)
WHERE a.monthA < b.monthB
Jt2ouan
  • 1,964
  • 9
  • 33
  • 55