mssql儲存過程-動態更新update
阿新 • • 發佈:2018-12-16
execute T_llj3 @pkmsg='abc';
select * from test_llj_1;
delete from test_llj_1;
drop proc T_llj3;
create proc T_llj3
@pkmsg char(12)
as
DECLARE @sqlu varchar(200) ;
DECLARE @sqls varchar(200) ;
DECLARE @sqlup varchar(200) ;
declare @tbnm varchar(200);
SET @sqlu= ' update '
SET @sqls= ' set STATUS=3 where MESSAGE_ID='
SET @sqlup = ''
select * from RECEIVE_MESSAGE where [email protected]
begin
DECLARE
c_test_main
CURSOR FAST_FORWARD FOR
SELECT
tbs.TABLE_NAME
FROM
INFORMATION_SCHEMA.tables tbs
WHERE
tbs.TABLE_NAME LIKE 'RECEIVE_%'
OPEN c_test_main WHILE 1=1
BEGIN
FETCH NEXT
FROM
c_test_main
INTO
@tbnm
SET @ [email protected][email protected] [email protected] [email protected]
insert into test_llj_1 values(@sqlup);
IF @@fetch_status != 0 BREAK
END
--EXEC(@sqlu)
CLOSE c_test_main
-- 釋放遊標.
DEALLOCATE c_test_main
end
select * from test_llj_1;
delete from test_llj_1;
drop proc T_llj3;
create proc T_llj3
@pkmsg char(12)
as
DECLARE @sqlu varchar(200) ;
DECLARE @sqls varchar(200) ;
DECLARE @sqlup varchar(200) ;
declare @tbnm varchar(200);
SET @sqlu= ' update '
SET @sqls= ' set STATUS=3 where MESSAGE_ID='
SET @sqlup = ''
select * from RECEIVE_MESSAGE where
begin
DECLARE
c_test_main
CURSOR FAST_FORWARD FOR
SELECT
tbs.TABLE_NAME
FROM
INFORMATION_SCHEMA.tables tbs
WHERE
tbs.TABLE_NAME LIKE 'RECEIVE_%'
OPEN c_test_main WHILE 1=1
BEGIN
FETCH NEXT
FROM
c_test_main
INTO
@tbnm
SET @
insert into test_llj_1 values(@sqlup);
IF @@fetch_status != 0 BREAK
END
--EXEC(@sqlu)
CLOSE c_test_main
-- 釋放遊標.
DEALLOCATE c_test_main
end