Ich habe eine TabelleAktualisieren einer Spalte Cursor mit Schleifen
| code | descd | slnum |
|------|-------|-------|
| 10 | a | 0 |
| 10 | b | 0 |
| 12 | c | 0 |
| 12 | d | 0 |
| 11 | e | 0 |
| 11 | f | 0 |
Und ich habe slnum Spalte wie diese mit Cursor mit Schleifen
| code | descd | slnum |
|------|-------|-------|
| 10 | a | 1 |
| 10 | b | 2 |
| 12 | c | 1 |
| 12 | d | 2 |
| 11 | e | 1 |
| 12 | f | 3 |
So aktualisieren dieses Problem zu beheben? Ich habe wie dieser versucht, aber seine was mir nicht korrekte Ausgabe
DECLARE @value INT
DECLARE @s INT=1
DECLARE scursor CURSOR FOR
SELECT slnum
FROM trec
for update of slnum
OPEN scursor
FETCH NEXT FROM scursor
INTO @value
WHILE @@FETCH_STATUS = 0
BEGIN
if exists(select * from trec) -- missing
begin
update trec
set [email protected]
where current of scursor
select @[email protected]+1
end
else
begin
update trec
set [email protected]
where current of scursor
end
FETCH NEXT FROM scursor INTO @value
END
CLOSE scursor
DEALLOCATE scursor
müssen Sie verwenden Cursor das zu tun? Es gibt einfachere Lösung, ohne Cursor – Squirrel
so .. wie groß ist Ihr Tisch? – lordkain
ja !! Ich möchte Cursor ist eine Hausaufgabe –