我有一个存储过程,它检索3列项目的多行。我正在以DataTable的格式检索。当我调试它时,它给我错误必须声明SQL Server存储过程中的标量变量
必须声明标量变量@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 [email protected]'
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);
}
你为什么使用动态SQL呢? 'NotifyOn'的数据类型是什么? – 2012-08-11 07:56:05
NotifyOn数据类型是日期时间 – Shaggy 2012-08-11 08:05:15