0

3 列項目の複数行を取得するストアド プロシージャがあります。DataTable の形式で取得しています。デバッグするとエラーが発生します

スカラー変数 @Ticket を宣言する必要があります。

しかし、私はすでにそれを宣言しました。

ストアド プロシージャ:

BEGIN

Declare @Ticket Numeric(28,0)
Declare @SQL VarChar(Max)
Declare @SQLUpdate VarChar(Max)

 Set @SQL='Select @Ticket=Ticket,VendorTicket[Vendor Ticket],Comments From dbo.VendorTickets Where NotifyOn <= GetDate() And IsNull(NotifyOn,0)<>0 '
 Exec(@SQL)

 Set @SQLUpdate='Update dbo.VendorTicket Set NotifyOn=0 Where Ticket=@Ticket'
 Exec(@SQLUpdate)

END

ストアド プロシージャを呼び出すコード

SqlConnection oConn = null;
DataTable dtReturn = null;
try
{
getConnection(ref oConn, 1);
using (SqlStoredProcedure sspObj = new SqlStoredProcedure("dbo.usp_checkNotification", oConn, CommandType.StoredProcedure))
{
dtReturn = sspObj.ExecuteDataTable();
sspObj.Dispose();
}
closeConnection(ref oConn);
}
4

2 に答える 2

0
Select @Ticket=Ticket,VendorTicket[Vendor Ticket],Comments From dbo.VendorTickets Where NotifyOn <= GetDate() And IsNull(NotifyOn,0)<>0

選択の結果が変数 @Ticket に書き込まれることを意味するため、@Ticket はテーブル変数である必要がありますが、@Ticket Numeric(28,0) を宣言します。次のSQLスクリプトを使用して、必要なことを実行できます。

Update dbo.VendorTicket 
Set NotifyOn=0 
Where Ticket in (
      Select Ticket 
      from dbo.VendorTickets 
      Where NotifyOn <= GetDate() And IsNull(NotifyOn,0)<>0
      )
于 2012-08-11T08:17:51.257 に答える
0

なぜ動的 SQL を使用しているのですか?

これをするだけ

 Update dbo.VendorTickets
 Set NotifyOn=0 
 Where NotifyOn <= GetDate() 
 And NotifyOn IS NOT NULL

日時 (NotifyOn) を 0 に設定すると、1900-01-01 に設定されることに注意してください。

于 2012-08-11T07:57:03.257 に答える