Wrapping Text

  • In a query, I have a field that needs to wrap text.  Is there an SQL code for this?

  • Maybe you could add a bit more detail to what you are attempting to do.  If you are trying to get the data returned in the results window to wrap text in one of the columns in Enterprise Manager or Query Analyzer... that just ain't gonna happen!

    But if you are passing a query via an App or something... then have the application do the wrapping of the data.  My suggestion would be to have your UI control any data display formatting.... not your stored procedure or query.

    Mike Gercevich

  • Not sure if this is what you're after, but when I dynamically build a SQL string in an ActiveX Script and then save this string to the source SQL of a datapump, I add the "vbcrlf" function to have it wrap nicely in the properties view of the Transform Data Task.

    vbcrlf = carriage return + line feed

    ActiveX Script

     mySQL = "SELECT fieldname_1, " & vbcrlf

     mySQL = mySQL & "    fieldname_2, " & vbcrlf

     mySQL = mySQL & "    fieldname_3, " & vbcrlf

     mySQL = mySQL & "    etc...fieldname_n " & vbcrlf

     mySQL = mySQL & "FROM tablename " & vbcrlf

     ' Assign SQL Statement to Source of DataPump

     objDataPump.SQLStatement = mySQL

    Hope this helps!

    Brian

  • This should definitely be handled in the GUI, but something like this may work (although it doesn't handle spaces)

    create function dbo.string_wrap(@String varchar(8000), @WrapInterval int)

    returns varchar(8000)

    as

    begin

    declare @NewString varchar(8000)

     

    While @String <> ''

     BEGIN

      select

       @NewString  = isnull(@NewString, '') + left(@String, @WrapInterval) + char(10),

       @String  = substring(@String, @WrapInterval + 1, 8000)

     END

    return @NewString

    END

    Signature is NULL

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

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