How to view the first 2 rows in to single row
Table1
id name value size result
----------------------------------
001 rajan 100 280DD 100%
002 Vijayan 200 120DD 80%
003 Sidarth 300 150DD 90%
004 Rakesh 400 270DD 95%
...
I want to select first 2 row in to single row….
Expected Output
id id name name value value size size result result
---------------------------------------------------------
001 002 rajan vijayan 100 200 280DD 120DD 100% 80%
003 004 Sidarth Rakesh 300 400 150DD 270DD 90% 95%
.....
How to do this?
That works for me. Hope it help you.
Please try that if you stil need help.
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
close curs
deallocate curs
SELECT * FROM @TempTable