Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Scan of table
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Title:
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01312331
Message ID:
01312491
Views:
11
>Hi All, I have a SP which I would like to "call" once for every record in a table - e.g. in VFP I would do something like
>
>
>use mytable
>
>scan
>    EXEC MySP mytable.field1
>endscan
>
>
>
>I know it's frowned upon sequentially scanning a table in SQL server but I don't know of any other way - is this doable ?

If there is no other options to do this you could avoid CURSOR like this:
DECLARE @PK int         --(or any other appropriate type for PK of your table)
DECLARE @YourField1 int --(or any other appropriate type for Field1 of your table)
SELECT @PK         = PKField,
       @YourField1 = Field1
 FROM YourTable
      INNER JOIN (SELECT MIN(PKField) AS PKField FROM YourTable  WHERE /* Put your where clause here if any*/ ) Tbl1
ON YourTable.PKField = Tbl1.PKField

WHILE @PK IS NOT NULL
    BEGIN
       EXEC @YourField1
       SELECT @PK         = PKField,
              @YourField1 = Field1
         FROM YourTable
         INNER JOIN (SELECT MIN(PKField) AS PKField FROM YourTable  WHERE PKField > @PK AND /* Put additional where clause here if any*/ ) Tbl1
       ON YourTable.PKField = Tbl1.PKField
    END
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform