jeudi 21 juillet 2016

How to use variable on looping in SQL Server

I have some varchar variables like this:

@var1='data a', 
@var2='data b',
@var3='data c', 
...,
@varn='data n'

I want to insert these variable on looping script.

DECLARE @counter INT
SET @counter = 1

WHILE(@counter <= n)
BEGIN
    UPDATE [table] 
    SET [header] 
    WHERE data = [@var1-n]

    SET @counter = @counter + 1
END
GO

How to make @var1 - @varn can use with loop on [@var1-n]?

Aucun commentaire:

Enregistrer un commentaire