我有一个包含以下 SQL 更新的 VB 代码:
UPDATE table_A SET UPD_FLG = 'N' WHERE UPD_FLG = 'Y'
我需要在单独的变量/记录集中找出上述查询更新的行数。目前我正在使用选择查询来获得相同的结果。但是有没有一种方法可以使用像 EXECUTE 这样的 VB 函数来完成呢?
我正在使用 VB 6.0
Set gCommand = New ADODB.Command
gCommand.CommandType = adCmdText
gCommand.CommandText = sSql1
gCommand.ActiveConnection = gconDb
gCommand.Execute (cnt)
为此,您可以对简单的程序进行如下操作:
CREATE PROCEDURE UpdateTables
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @RowCount1 INTEGER
DECLARE @RowCount2 INTEGER
DECLARE @RowCount3 INTEGER
DECLARE @RowCount4 INTEGER
UPDATE Table1 Set Column = 0 WHERE Column IS NULL
SELECT @RowCount1 = @@ROWCOUNT
UPDATE Table2 Set Column = 0 WHERE Column IS NULL
SELECT @RowCount2 = @@ROWCOUNT
UPDATE Table3 Set Column = 0 WHERE Column IS NULL
SELECT @RowCount3 = @@ROWCOUNT
UPDATE Table4 Set Column = 0 WHERE Column IS NULL
SELECT @RowCount4 = @@ROWCOUNT
SELECT @RowCount1 AS Table1, @RowCount2 AS Table2, @RowCount3 AS Table3, @RowCount4 AS Table4
END
参考:
或者
在 VB 中使用此过程: