0

私はMicrosoftSQLServer R2 2008を持っています。そして、人生で初めてそれを目にします。
私はSQLプロシージャを持っています:

DECLARE @RC int
DECLARE @Id uniqueidentifier
DECLARE @Segment_ID uniqueidentifier
DECLARE @SDate datetime
DECLARE @EDate datetime
DECLARE @withBig bit
DECLARE @withKm bit
DECLARE @withGeo bit
DECLARE @withDescr bit

-- TODO: задайте здесь значения параметров.

EXECUTE @RC = [Request_BusStation] 
   @Id
  ,@Segment_ID
  ,@SDate
  ,@EDate
  ,@withBig
  ,@withKm
  ,@withGeo
  ,@withDescr
GO

それ自体ではなく、手順の呼び出しだけを理解する方法。しかし、手順が少なすぎてここにコピーできません。そして、テーブルを持っています:

   CREATE TABLE [BusStation](
[Id] [uniqueidentifier] NOT NULL,
[Segment_ID] [uniqueidentifier] NOT NULL,
[Dist] [decimal](18, 4) NOT NULL,
[Kod_Spr012] [smallint] NOT NULL,
[Square] [decimal](18, 6) NULL,
[OperationStartDate] [date] NULL,
[BallanceCost] [decimal](18, 6) NULL,
[DepreciatedCost] [decimal](18, 6) NULL,
[ChargesNorm] [decimal](18, 6) NULL,
[DocumentName] [varchar](100) NULL,
[DocumentNum] [varchar](100) NULL,
[DocumentDate] [date] NULL,
[Authority] [varchar](100) NULL,
[Kod_Spr091] [smallint] NOT NULL,
[HasWaysideStop] [bit] NOT NULL,
[HasLanding] [bit] NOT NULL,
[HasSpeedTransitArea] [bit] NOT NULL,
[LenSpeedTransitArea] [decimal](18, 6) NULL,
[YearBuilt] [smallint] NULL,
[YearMajorOverhaul] [smallint] NULL,
[Kod_Spr019] [smallint] NOT NULL,
[TechCond] [varbinary](max) NULL,
[LandCont] [varbinary](max) NULL,
[LandContDate] [date] NULL,
[LandContStartDate] [date] NULL,
[LandContEndDate] [date] NULL,
[Kod_Spr120] [smallint] NULL,
[E_Date_Begin] [datetime] NOT NULL,
[E_Date_End] [datetime] NULL,
[E_Date_Stop] [datetime] NULL,

ここで、テーブルの各行に対してこのプロシージャを呼び出します。
それが可能だ?

4

2 に答える 2

3

はい、テーブル内のすべての行を選択し、ストアド プロシージャを繰り返し呼び出すカーソルを使用できます。

ただし、そのルートをたどる前に、設計上の問題がある可能性があることをお勧めします。テーブル内のすべての行に対してストアド プロシージャを呼び出す必要がある場合は、単一の行操作ではなく、現在の sp がすべての行に対して行っていることを単純に実行するストアド プロシージャを作成できる場合があります。

あなたはspが何をしているのかを提供していないので、ここでは推測することしかできません.

于 2013-01-29T16:39:50.567 に答える
1

私のコメントで述べたように、それを行う方法を知る唯一の方法は、を使用することCURSORです。ここにいくつかのサンプルコードがあります(もちろんテストされていません):

DECLARE @ID INT
DECLARE @Segment_ID uniqueidentifier

DECLARE @getAccountID CURSOR
SET @BusStationCursor = CURSOR FOR
SELECT Id, Segment_ID --(etc: all the fields you need)
FROM BusStation

OPEN @BusStationCursor
FETCH NEXT    FROM @BusStationCursor INTO @ID, @Segment_ID
WHILE @@FETCH_STATUS = 0
BEGIN

--CALL YOUR SP HERE
PRINT @ID 
PRINT @Segment_ID

FETCH NEXT    FROM @BusStationCursor INTO @ID, @Segment_ID
END
CLOSE @BusStationCursor
DEALLOCATE @BusStationCursor

これも役立つはずです:

http://msdn.microsoft.com/en-us/library/ms180169.aspx

幸運を。

于 2013-01-29T16:39:25.390 に答える