Welcome to Sign in | Help

Re: Intrebare de pe ITboard - Refactor Cursor to SELECT

  •  10-10-2006, 1:19 PM

    Re: Intrebare de pe ITboard - Refactor Cursor to SELECT

    DECLARE @MyTable TABLE (ID INT PRIMARY KEY, VAL VARCHAR(64))

     

    INSERT INTO @MyTable VALUES (1, 'Cristian')

    INSERT INTO @MyTable VALUES (2, 'Sorin')

    INSERT INTO @MyTable VALUES (3, 'Narcis')

     

    DECLARE @Lista VARCHAR(MAX)

    SET @Lista = '';

     

    SELECT @Lista=@Lista + VAL + ' ' FROM @MyTable

     

    SELECT RTRIM(@Lista) AS Lista

    GO

     

    -- Output

    Lista

    Cristian Sorin Narcis


    Cristian Andrei Lefter, SQL Server MVP
    MCT, MCSA, MCDBA, MCAD, MCSD .NET,
    MCTS, MCITP - Database Administrator SQL Server 2005
    http://sqlserver.ro
View Complete Thread
Powered by Community Server (Commercial Edition), by Telligent Systems