Demo for Bhupinder Singh

0

Please login or register to vote for this query.

(click on this box to dismiss)

For SO question http://stackoverflow.com/q/8109272/939860

Stack Overflow

Q&A for professional and enthusiast programmers

-- Demo for Bhupinder Singh
-- For SO question http://stackoverflow.com/q/8109272/939860

CREATE TABLE #t
(   ID INT PRIMARY KEY,
    [set] INT,
    status CHAR(20),
    message CHAR(20)
)

INSERT #t VALUES
 (1, 1, NULL,    NULL)
,(2, 1, 'MATCH', NULL)
,(3, 3, NULL,    NULL)
,(4, 3, 'MATCH', NULL)
,(5, 2, NULL,    NULL)
,(6, 2, NULL,    NULL)

;WITH s AS (
      SELECT [set]
            ,'VOID' AS stat
            ,('FOR ID = ' + CAST (ID AS char)) AS msg
      FROM   #t
      WHERE  status = 'MATCH'
  )
UPDATE #t
SET    status  = s.stat
      ,message = s.msg
FROM   s
WHERE  #t.status IS NULL
AND    (s.[set] = #t.[set] OR s.[set] IS NULL)

SELECT * FROM #t;

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results