暂时更改SQL数据

时间:2014-12-06 17:59:21

标签: sql sql-server

我想知道是否有可能暂时更改SQL中的数据

七月,八月和九月我有三个月的时间。我想将它们分别更改为1,2和3,以便我可以执行以下操作:

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

我知道这有效

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')

1 个答案:

答案 0 :(得分:0)

听起来你只想将varchar数据暂存为1,2,3并且不一定在数据库中更改它是正确的吗?

为什么不用case stmt将值更改为1,2,3,然后执行您需要的操作。

 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