Results 1 to 6 of 6

Thread: avoid using sp

  1. #1
    Join Date
    Aug 2003
    Location
    London
    Posts
    110

    avoid using sp

    hi,

    I have a table like

    A B C
    --- ------- -----
    Tim jones text1
    Tim jones text2
    ....

    and I want to group the result by A,B and C(is string) , normaly if C is number you can use Sum() or other aggregate functions.
    with out using Store procedure is there any way to achive following result.

    result

    A B C
    --- ------- -----
    Tim jones text1text2
    ...


    Thanks

    S

  2. #2
    Join Date
    Feb 2003
    Posts
    1,048
    There isn't a function for this, but you can create your own user defined function and call it inline in a query .... assuming that you are using a database that supports that.

  3. #3
    Join Date
    Aug 2003
    Location
    London
    Posts
    110
    Thanks,can you please help me with coding the funtion

  4. #4
    Join Date
    Nov 2002
    Location
    DE
    Posts
    246
    Please tell us which DBMS you are working with.

  5. #5
    Join Date
    Aug 2003
    Location
    London
    Posts
    110
    sql server 2000 enterprise

  6. #6
    Join Date
    Nov 2002
    Location
    DE
    Posts
    246
    CREATE FUNCTION dbo.udf_ConcatText (@A varchar (50), @B varchar (50)) RETURNS varchar (4000) AS
    BEGIN
    DECLARE @temp varchar (4000)
    SET @temp = ''
    SELECT @temp = @temp + ISNULL (C)
    FROM yourtable
    WHERE A = @A AND B = @B

    Return (@temp)
    END
    GO

    And you can use it like this:

    SELECT A, B, dbo.udf_ConcatText (A, B)
    FROM yourTable

Posting Permissions

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