在sql中连接两列

时间:2014-02-28 12:09:14

标签: sql sql-server

我在数据gridview上有四列,希望它们在sql中连接并将其导出到txt文件,但每次导出时都是我的结果。

我的结果

0010000 01500 00000 0001600 

需要输出

001000001500000000001600 

SQL查询:

 string stringSql = " SELECT distinct  " +
     "REPLACE(RIGHT('00'+CAST(CAST(bat.PCN_Charge* 100.00 AS INT) AS VARCHAR(5)),8) as CLAIMAMT, + RIGHT('0'+CAST(CAST([CFee] * 100 AS INT) AS VARCHAR(5)),5),' ','' )as CFEE," +
      "REPLACE(RIGHT('00000'+CAST(CAST([Solictors Fees]  AS INT) AS VARCHAR(5)),5), + RIGHT('000'+CAST(CAST(bat.PCN_Charge + [CFee]*100 AS INT) AS VARCHAR(5)),9),' ','') as TotalAMT " +

4 个答案:

答案 0 :(得分:0)

从手册来看:

方法1:连接两个字符串

SELECT 'FirstName' + ' ' + 'LastName' AS FullName

方法2:连接两个数字

SELECT CAST(1 AS VARCHAR(10)) + ' ' + CAST(2 AS VARCHAR(10))

方法3:连接表列的值

SELECT FirstName + ' ' + LastName
FROM AdventureWorks.Person.Contact

在你的情况下,你应该这样做,避免两者之间的空间。

答案 1 :(得分:0)

select first_column+' '+second_c+' '+third_c+' '+forth_c
from table_name

答案 2 :(得分:0)

试试吧

declare @result varchar(500)
set @result = ''
select @result = @result +' '+first_c+' '+second_c+' '+third_c+' '+forth_c
from table_name

答案 3 :(得分:0)

declare @a varchar(50) 
set @a='0010000 01500 00000 0001600'
select replace(@a,' ','')

SEE DEMO