0

I have an sql string retreiving data for three columns and I dont want any space in betweeen these columns. I want to remove space between columns.

 string stringSql = " SELECT distinct  " +
                   "'" + comboBox6.Text + "' as RecordType" +
                 " , left([Claimant Name] +' ',29) " +
                " , left([Claimant Address1] +' ',29)  " +
                " , left([Claimant Address2] +' ',29) as ClaimantAddress2 " +

My Client requirment is like

**1xyz1dundas**

MY output is like

**1 xyz 1 dundas**
Jim G.
  • 15,141
  • 22
  • 103
  • 166
preethi
  • 885
  • 5
  • 20
  • 39

4 Answers4

4

Make use of replace

stringSql .Replace("  ", string.empty);

in sql

 SELECT REPLACE(stringSql, ' ', '')
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
2

In case you want to remove whitespaces (not just ordinary spaces ' ', but, say, tabluations '\t') you can use LINQ:

  stringSql = new String(stringSql.Where(x => !Char.IsWhiteSpace(x)).ToArray());
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
1

On SQL-Server:

SELECT REPLACE(yourField, ' ', '')
Fabian Bigler
  • 10,403
  • 6
  • 47
  • 70
0

MSSQL Server :

RTRIM(LTRIM(a))

Oracle , MySQL, SQL Server 2012 : TRIM Function

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 "