Sql server c#删除字符串中的所有空格
我有一个sql字符串,用于检索三列的数据,我不希望这些列之间有任何空间。我想删除列之间的空格Sql server c#删除字符串中的所有空格,sql-server,Sql Server,我有一个sql字符串,用于检索三列的数据,我不希望这些列之间有任何空间。我想删除列之间的空格 string stringSql = " SELECT distinct " + "'" + comboBox6.Text + "' as RecordType" + " , left([Claimant Name] +' ',29) " + " , left([Claimant Address1
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, ' ', '')
在SQL Server上:
SELECT REPLACE(yourField, ' ', '')
如果您想删除空白(不仅仅是普通空格
'
,还可以使用LINQ:
stringSql = new String(stringSql.Where(x => !Char.IsWhiteSpace(x)).ToArray());
MSSQL服务器:
RTRIM(LTRIM(a))
Oracle、MySQL、SQL Server 2012:修剪功能
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 "
首先不添加空格怎么样?每列都有特定的字符长度。sQL server mangament Studio始终使用参数化查询以避免sQL注入您的问题不清楚。如果索赔人的姓名或地址之间有空格怎么办。我们是否也应该删除该选项,例如,7月1日的街道应成为7月1日的街道,还是只删除结尾空格?另一点是要知道您的列是CHAR数据类型还是VARCHAR/NVARCHAR