Home Forums SQL Server 2008 SQL Server 2008 - General Some way to create a deterministic computed column that only has to count once? RE: Some way to create a deterministic computed column that only has to count once?

  • I'm not sure if anybody is still following this thread but I came across something recently that might apply:

    DECLARE @x TABLE (

    [RecID] INT IDENTITY(1,1)

    ,[Name] VARCHAR(11)

    ,[Flag] TINYINT DEFAULT(0)

    ,[ProcessRecID] INT NULL

    )

    DECLARE @recid INT

    INSERT INTO @x ([Name])

    VALUES

    ('Apple')

    ,('Banana')

    ,('Cherry')

    ,('Date')

    ,('Elderberry')

    ,('Fig')

    ,('Grape')

    ,('Huckleberry')

    UPDATE @x

    SET [Flag] = 1

    WHERE [Name] IN ('Apple', 'Banana', 'Fig')

    --SELECT * FROM @x

    SELECT @recid = 0

    UPDATE @x

    SET @recid = [ProcessRecID] = @recid + 1

    WHERE [Flag] = 1

    SELECT * FROM @x