Home Forums SQL Server 2008 T-SQL (SS2K8) how to replace this cursor with set based solution? RE: how to replace this cursor with set based solution?

  • Very nice of you Sean.

    Aliased the table variable, and referenced the values in the table variable with column name.

    worked:

    DECLARE @benches TABLE (Bench varchar(20));

    INSERT @benches

    values

    ('LabC1'),

    ('LabC2'),

    ('LabC3'),

    ('LabC4');

    INSERT INTO RunsByBench

    SELECT

    Bench as BenchName,

    COUNT(CreateDate) AS NumberOfRunsOnBench,

    MAX(CreateDate) AS LastRun

    FROM @benches b

    OUTER APPLY dbo.GetBench(b.bench)

    group by Bench;

    --Quote me