I'm trying to save a value in a variable.
I create the table and insert records.
CREATE TABLE #TEMP (IDSOL INT not null PRIMARY KEY ,USUARIO VARCHAR(50) ,LastName varchar(255) NOT NULL,FirstName varchar(255),Age int, )
INSERT INTO #TEMP
VALUES(1,'ADMIN','RODRIGUEZ','LOPEZ',20)
INSERT INTO #TEMP
VALUES(2,'ADMIN','YAÑEZ','CARROL',20)
INSERT INTO #TEMP
VALUES(3,'ADMIN','MONS','JAFET',20)
Then I need to set the column IDSOL
in a variable so I'm using a WHILE
this is what I have.
DECLARE @I INT
DECLARE @J INT
DECLARE @VALOR_IDSOL
SET @I = (SELECT COUNT(*) FROM #TEMP WHERE USUARIO = 'ADMIN')
SET @J = 1
WHILE @I >= @J
BEGIN
SET @VALOR_IDSOL = (SELECT IDSOL FROM #TEMP WHERE USUARIO = 'ADMIN')
SET @J = @J + 1
END
I get the number of records in the query and then I pass the same number of records for the WHILE
I want to get the value IDSOL
of the first record and in the next round the second record and in the third round the same and that way until it's over, someone can give me some idea.