【发布时间】:2018-05-01 23:39:37
【问题描述】:
我有一个类似的表,服务器是 SQL Server 2008 R2,我们不能使用 concat 函数
YearID | MonthId
--------+----------
2017 | 1
2014 | 5
2014 | 10
2016 | 12
我希望输出为
201701
201405
201410
201612
到目前为止我尝试了什么
select
cast(YearId as varchar(50)) + '0' + cast(MonthId as varchar(50))
from
TEST
我得到的输出为
201701
201405
2014010
2016012
monthID 为 2 位时,表示失败。
如何应对这种情况?
【问题讨论】:
标签: sql sql-server tsql sql-server-2008-r2 concatenation