sql查询语句(在线等)
假如t1表里有 四个字段a,b,c,d:
a b c d
0 1 0 3
0 2 3 1
如何通过查询语句得到他们的组合,即
0103
0231
------解决方案--------------------select cast(a as varchar)+cast(b as varchar)+cast(c as varchar)+cast(d as varchar) from t1
------解决方案--------------------select abcd=ltrim(a)+ltrim(b)+ltrim(c)+ltrim(d) from [t1]
------解决方案--------------------楼上正解
------解决方案--------------------select abcd=ltrim(isnull(a, ' '))+ltrim(isnull(b, ' '))+ltrim(isnull(c, ' '))+ltrim(isnull(d, ' ')) from t1
------解决方案--------------------如果a b c d 是數值型
select isnull(cast(a as varchar(100)), ' ')+isnull(cast(b as varchar(100)), ' ')+isnull(cast(c as varchar(100)), ' ')+isnull(cast(d as varchar(100)), ' ') from t1
如果a b c d 是字符型
select abcd=ltrim(isnull(a, ' '))+ltrim(isnull(b, ' '))+ltrim(isnull(c, ' '))+ltrim(isnull(d, ' ')) from t1