Thursday, July 31, 2014

How to implement poor-man's version control with TSQL queries

Should this work? It prints all the rows.



DECLARE @Projects TABLE
([id] int IDENTITY(1,1), [Project] varchar(1), [Version] int)
;

INSERT INTO @Projects
([Project], [Version])
VALUES
('A', 1),
('A', 2),
('A', 3),
('A', 4),
('B', 1),
('B', 2),
('B', 3),
('C', 1),
('C', 2),
('D', 1)
;


-- DECLARE @User varchar(100)

SELECT *
FROM @Projects p
WHERE
-- UserName = @User AND
NOT EXISTS (SELECT 1
FROM @Projects q
WHERE q.id = p.id
AND q.Version < p.Version)






siegfried heintze


No comments:

Post a Comment