这个问题在这里已有答案:
我有一个sql字符串检索三列的数据,我不希望这些列之间有任何空格。我想删除列之间的空格。
string stringSql = " SELECT distinct " +
"'" + comboBox6.Text + "' as RecordType" +
" , left([Claimant Name] +' ',29) " +
" , left([Claimant Address1] +' ',29) " +
" , left([Claimant Address2] +' ',29) as ClaimantAddress2 " +
我的客户要求就像
**1xyz1dundas**
我的输出就像
**1 xyz 1 dundas**
利用替换
stringSql .Replace(" ", string.empty);
在sql中
SELECT REPLACE(stringSql, ' ', '')
如果你想删除空格(不只是普通空格' '
,但是,比如说,表格'\t'
)你可以使用LINQ:
stringSql = new String(stringSql.Where(x => !Char.IsWhiteSpace(x)).ToArray());
在SQL-Server上:
SELECT REPLACE(yourField, ' ', '')
MSSQL服务器:
RTRIM(LTRIM(a))
Oracle,MySQL,SQL Server 2012:TRIM功能
string stringSql = " SELECT distinct " +
"'" + comboBox6.Text + "' as RecordType" +
" , RTRIM(LTRIM(left([Claimant Name] +' ',29))) " +
" , RTRIM(LTRIM(left([Claimant Address1] +' ',29))) " +
" , RTRIM(LTRIM(left([Claimant Address2] +' ',29))) as ClaimantAddress2 "