Query Help

  • Hi All

    I need one logical help to implement in my main logic.

    so please help me to do

    create table #x1

    (SchoolID int,

    SchoolName Varchar(50))

    INSERT INTO #x1 VALUES (101,'CITY CONNECTIONS-WEST')

    INSERT INTO #x1 VALUES (102,'City Connections - South')

    I need space around hyphens where SchoolName has no space around Hyphes.

    SchoolIDSchoolName

    101CITY CONNECTIONS-WEST

    102City Connections - South

    Expected output is as below

    SchoolIDSchoolName

    101CITY CONNECTIONS - WEST

    102City Connections - South

    Please help me to do this

    Thanks for Your Help

  • SELECT SchoolID

    ,REPLACE(REPLACE(SchoolName, '-',' - '),' - ',' - ') AS SchoolName

    FROM #x1

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Eugene Elutin (7/3/2013)


    SELECT SchoolID

    ,REPLACE(REPLACE(SchoolName, '-',' - '),' - ',' - ') AS SchoolName

    FROM #x1

    Hi

    Unfortunately this will leave double spaces for strings like 'One -two'

    A little change

    SELECT SchoolID

    ,REPLACE(REPLACE(SchoolName, '-',' - '),' ',' ') AS SchoolName

    FROM #x1

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply