Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2005
    Posts
    36

    Unanswered: New line in query

    Hi,
    I was wondering if there is any way I can place a new line inside a query...

    e.g.

    select field1 + 'NEWLINE' + field2 from tablename


    I want to place a new line between field1 and field2

    Thanks in advance

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    select field1 + char(13) + field2 from tablename
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Apr 2005
    Posts
    36
    Thanks for reply blindman

    I have tried this already but it doesn't work
    any other suggestions would be appreciated.


    Thanks

  4. #4
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    It works in query analyzer. What are you looking at the results in?
    Code:
    select 'a' + char(13) + 'b'

  5. #5
    Join Date
    Apr 2005
    Posts
    36
    I am using MSSQL 2005 Server Management Studio which replaces both the SQL Server 2000 Enterprise Manager and the Query Analyzer.

    Thanks

  6. #6
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    Odd. It still works for me.
    Code:
    select 'a' + char(13) + 'b'
    
    ----
    a
    b
    
    (1 row(s) affected)

  7. #7
    Join Date
    Apr 2005
    Posts
    36
    Actually It works on the text mode result but not Grid mode ...still it doesn't save a and b on different lines in the database itself not sure why

    Once I fetch the record it displays it on a single line....

    On my other fields where I am saving text from my .net application textboxes it creates double boxes for a newline... I was wondering how would I create thoes double boxes
    Last edited by azshah; 10-05-06 at 16:49.

  8. #8
    Join Date
    Jul 2006
    Posts
    87
    Ahh, the grid is saving the carriage return, but it displays as a blank in grid mode.

    Code:
    -- Using Northwind
    
    DECLARE @MyText  CHAR(26)
    DECLARE @MyText2 CHAR(26)
    SET     @MyText = 'a' + char(13) + 'b'
    PRINT   @MyText
    
    SELECT ShipCity 
    FROM   Orders 
    WHERE  OrderID = 10248
    
    UPDATE Orders 
    SET    ShipCity = @MyText
    WHERE  OrderID  = 10248
    
    SET @MyText2 = (SELECT ShipCity 
    FROM   Orders 
    WHERE  OrderID = 10248)
    
    PRINT   @MyText2
    
    SELECT ShipCity 
    FROM   Orders 
    WHERE  OrderID = 10248
    
    UPDATE Orders 
    SET    ShipCity = 'Reims'
    WHERE  OrderID  = 10248
    Run this in text mode and you will see that the newline is saved.
    Run this in grid mode and you will see that the newline is converted.

    I hope this helps,
    Code Carpenter
    Code:
    If this.Helped
    Then Say("Thank You")
    Else Goto 'Help'

  9. #9
    Join Date
    Apr 2005
    Posts
    36
    Still it will show a one straight line when fetching that data .....what I am thinking now is create a tiny function in .net and add new lines there it did worked for my other data before.....


    "thank you all for the help guys this forum ROCKS "

  10. #10
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Why are you concerned with how it looks in Management Studio? Neither Management Studio or Query Analyzer is meant to be used as a user interface or reporting tool.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •