【发布时间】:2023-04-05 16:43:01
【问题描述】:
我在 sql server 中有 3 列的下表。我想将 [yearmonth] 与 [year] 和 [month] 列的串联进行比较。比如... select count(*) from table where [yearmonth]=concat([year],[month])。
在这里,当我们有一个单位数的 [month] 值时,我们必须在其中添加 0 作为前缀。就像第一条记录一样,在比较时它应该变成 05 而不是 5。所以 select count(*) from table where [yearmonth]=concat([year],[month]) 的最终计数应该是 3
[年月]的数据类型是nvarchar
[年份]的数据类型是nvarchar
[month] 的数据类型是 int
【问题讨论】:
-
您的实际问题是什么?如何从
int值2021和5中获取'202105'? -
嗨@Larnu..请检查线程中的以下解决方案..这就是我想要的..感谢您的调查。
-
列有哪些类型?如果他们是
int,那么你可以做year * 100 + month
标签: sql sql-server