今天在SQLserver中做了一个多重拼接的语句,将4~5个字符串进行拼接,其中一个是varchar类型,剩下的都是int类型,众所周知 int类型与varchar类型进行拼接需要进行类型的转换,于是有了下面的语句
select concat(铸件工艺单细则.备注,
(case
when 铸件工艺单细则.底面贴量 is not null then ‘底面贴量’+convert(varchar(50),
底面贴量)+‘mm’
end) +(case
when 铸件工艺单细则.侧上贴量 is not null then ‘侧上贴量’+convert(varchar(50),
侧上贴量)+‘mm’
end) +(case
when 铸件工艺单细则.侧面贴量 is not null then ‘侧面贴量’+convert(varchar(50),
侧面贴量)+‘mm’
end) +(case
when 铸件工艺单细则.吊耳贴量 is not null then ‘吊耳贴量’+convert(varchar(50),
吊耳贴量)+‘mm’
end) +(case
when 铸件工艺单细则.底面凸台贴量 is not null then ‘底面凸台贴量’+convert(varchar(50),
底面凸台贴量)+‘mm’
end) ) as 贴量
from 铸件工艺单细则
case when 先识别是否为空,然后进行类型转换,最后在进行拼接,但是结果发现,当其中有一个int有数值的情况下,但是结果出来的却是null,遂将语句单个拿出进行测试,发现结果没有问题,那么问题就是出在拼接上面ÿ