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



Nope you have condition wrong


In my suggestion i've used > and you replaced it with <


it should be this



SELECT *
FROM @Projects p
WHERE
NOT EXISTS (SELECT 1
FROM @Projects q
WHERE q.project= p.projects
AND q.Version > p.Version)





Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://ift.tt/19nLNVq http://ift.tt/1iEAj0c


No comments:

Post a Comment