Quantcast
Channel: SQL Server Express Forum
Viewing all articles
Browse latest Browse all 484

Ausgabe des Ergebnisses einer StoredProcedure in Tabeelle

$
0
0

Meine sehr komplexe StoredProcedure [SP_count]

liefert genau einen Wert , eine Anzahl (Anz), wobei eine ID übergeben wird:

exec [SP_count]    @ObjNo

So, jetzt will ich diese SP aber nicht einzeln für eine bestimmte ID aufrufen, sondern für eine ganze Liste von IDs, die man so erhält

Select ObjNo from Tabellexxx where [Bedingung]

OK, so würde es im Prinzip gehen:

go
Declare @ObjNo as integer;
DECLARE @Tab as table (Objectno integer, Anz int);
Create table #Tab  (Objectno integer, Anz int);

Set @ObjNo = 1;
While @ObjNo < 100
begin
     insert into #Tab( ObjectNo, Anz )
     exec [SP_count]    @ObjNo;
        Update    #Tab set Objectno =    @ObjNo where Objectno is Null;
        Set @ObjNo = @ObjNo + 1 ;
end;
select * from #Tab;
 drop table #Tab;
go

Aber ich will ja statt von 1 bis xxx ja die IDs aus der obigen Abfrage einbauen. D.h. wie mancht man eine Schleife über die Abfrage?


Viewing all articles
Browse latest Browse all 484


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>