Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2006

    Unanswered: Select string concatenation

    I want to concatanate all text rows returned by the following sql statement:

    "SELECT Text FROM PageText WHERE PageTextId = 1"

    Table "PageText" has the following columns:
    PageTextId (int)
    SortOrder (int)
    Text (nvarchar(4000))

    Is it possible to do this? Kinda like doing a "SUM()" if the values would have been numeric?

  2. #2
    Join Date
    Jun 2003
    u can do by below code,only limitation is, maximum size of nvarchar is 4000.
    set nocount on
    declare @texts as nvarchar(4000)
    set @texts =''
      @texts =@texts+coalesce(Text,'')
               PageTextId = 1
    print @texts
    Last edited by mallier; 03-14-06 at 04:54.
    I love cursor,though I never use it.Cos' I dont want to misuse it.


  3. #3
    Join Date
    Mar 2006
    mallier, thx for ur reply.

    I wanted to get away from using ntext and instead use varchar(4000) divided into several rows, to maintain performance. I wanted to put the logic of concatenating these rows in a stored proc. I realized though, after I did my post, that I will not be able to return a varchar. I would have to return a ntext. The "divide in several rows" strategy would then be of no use, since I would be using ntext anyway. I am now doing the "concatenating of strings" part in my code.

Posting Permissions

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