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.
  • 14,600
  • 19
  • 100
  • 158
preethi
  • 855
  • 5
  • 16
  • 37

4 Answers4

4

Make use of replace

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

in sql

 SELECT REPLACE(stringSql, ' ', '')
Sajeetharan
  • 203,447
  • 57
  • 330
  • 376
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
  • 165,109
  • 17
  • 150
  • 199
1

On SQL-Server:

SELECT REPLACE(yourField, ' ', '')
Fabian Bigler
  • 9,721
  • 6
  • 41
  • 64
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 "