Replicate Help

  • Hi All,

    Please read my query:

    DECLARE @tblRecursosArbol TABLE (

    id BIGINT IDENTITY(1, 1),

    id_recurso INT,

    id_recurso_padre INT,

    nivel INT,

    familia INT,

    tree VARCHAR(150) NULL

    )

    INSERT @tblRecursosArbol

    SELECT 1127107,1127107,1,3,NULL UNION ALL

    SELECT 1127106,1127106,1,2,NULL UNION ALL

    SELECT 1125709,1127106,2,2,NULL UNION ALL

    SELECT 1125710,1125709,3,2,NULL UNION ALL

    SELECT 1125711,1125710,4,2,NULL UNION ALL

    SELECT 1125712,1125709,3,2,NULL UNION ALL

    SELECT 1125707,1125712,4,2,NULL UNION ALL

    SELECT 1125708,1125707,5,2,NULL UNION ALL

    SELECT 1127108,1127106,2,2,NULL UNION ALL

    SELECT 1125710,1127108,3,2,NULL UNION ALL

    SELECT 1125711,1125710,4,2,NULL UNION ALL

    SELECT 1127105,1127105,1,1,NULL

    SELECT id_recurso,nivel,

    CASE

    WHEN T.nivel=1 THEN ''

    ELSE REPLICATE('_',t.nivel)

    END + CONVERT(VARCHAR(50),T.id_recurso)

    FROM @tblRecursosArbol T

    depending on the nivel i have to generate a differential in the record with: ('_'), I applied the function REPLICATE, but if we speak of thousands of records is well apply it? i mean, i think the perfomance will be lost.

    Any Recommendations please?

    Thanks.

    ____________________________________________________________________________
    Rafo*

  • I don't think this will get too slow, even on a big input.

    Anyway, I can't think of any other efficient way to generate that prefix.

    -- Gianluca Sartori

  • I agree with Gianluca. There really doesn't seem to be a reason that this won't perform well with more rows, since this is still a set-based operation.

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

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