select rtrim(scid)+replicate(' ',1)+rtrim(id) from table
---测试数据--- if object_id('[tb]') is not null drop table [tb] go create table [tb]([id] int,[scid] int) insert [tb] select 1,0 union all select 2,0 union all select 3,0 union all select 4,1 union all select 5,0 union all select 6,1 union all select 7,2
---查询--- select ltrim(id)+' '+ltrim(scid) as a from [tb]---结果--- a ------------- 1 0 2 0 3 0 4 1 5 0 6 1 7 2(7 行受影响)
---查询--- select ltrim(scid)+' '+ltrim(id) as a from [tb]---结果--- /** a ------- 0 1 0 2 0 3 1 4 0 5 1 6 2 7 **/
select
rtrim(scid)+replicate(' ',1)+rtrim(id)
from table
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([id] int,[scid] int)
insert [tb]
select 1,0 union all
select 2,0 union all
select 3,0 union all
select 4,1 union all
select 5,0 union all
select 6,1 union all
select 7,2
---查询---
select ltrim(id)+' '+ltrim(scid) as a from [tb]---结果---
a
-------------
1 0
2 0
3 0
4 1
5 0
6 1
7 2(7 行受影响)
select ltrim(scid)+' '+ltrim(id) as a from [tb]---结果---
/**
a
-------
0 1
0 2
0 3
1 4
0 5
1 6
2 7
**/