解释一下!
各位,本鸟读懂该段实有难度,恳请诸位高手帮忙解释下!附上演示实例。谢谢!
select @equipment_id = rtrim(Convert(char(3),Convert(int,substring(max(equipment_id),4,3))+1)) from tb_er_equipment
select @equipment_id = 'VIS'+REPLICATE('0', 3 - datalength(rtrim(@equipment_id)))+rtrim(@equipment_id)
------解决方案--------------------
rtrim(Convert(char(3),Convert(int,substring(max(equipment_id),4,3))+1))
max(equipment_id) 取最大值
substring(max(equipment_id),4,3) 截字符串,从第四个开始,截三个
Convert(int,substring(max(equipment_id),4,3))+1)
截出来的字符串 转换 INT 然后+ 1
Convert(char(3),Convert(int,substring(max(equipment_id),4,3))+1))
转换为 char 类型
REPLICATE('0', 3 - datalength(rtrim(@equipment_id)))+rtrim(@equipment_id)
rtrim(@equipment_id) 去空格
datalength(rtrim(@equipment_id)) 取长度
REPLICATE('0', 3 - datalength(rtrim(@equipment_id)))
返回一个值,如000000,0的位数,决绝于 3 - datalength(rtrim(@equipment_id))
rtrim(@equipment_id) 去空格