SELECT
t.Id, tt.Id, t.name, tt.name, t.value, tt.value, t.size, tt.size, t.result, tt.result
FROM YourTable t
INNER JOIN YourTable tt ON tt.Id = t.Id + 1
WHERE tt.Id % 2 = 0
这对我行得通。希望对您有所帮助。
如果您仍然需要帮助,请尝试一下。
Declare @TempTable as table (FirstId int, SecondId int null, FirstCaption nvarchar(max), SecondCaption nvarchar(max) null, FirstDescription nvarchar(max), SecondDescription nvarchar(max) null)
DECLARE @TempId int DECLARE curs CURSOR FOR SELECT ID FROM Categories open curs fetch next from curs into @TempId WHILE @@FETCH_STATUS = 0 begin IF (@TempId % 2 = 1) BEGIN INSERT INTO @TempTable SELECT t.Id, null, t .Caption, null, t.Description, null FROM categories t WHERE t.Id = @TempId
END
ELSE
BEGIN
UPDATE @TempTable SET SecondId = t.Id, SecondCaption = t.Caption, SecondDescription = t.Description
FROM categories t
INNER JOIN @TempTable tt ON tt.FirstId = @TempId - 1
WHERE t.Id = @TempId
END
fetch next from curs into @TempId
结束关闭 curs 解除分配 curs
选择 * 从 @TempTable