The last written memory process, you need to return parameters from the execution of the string, use sp_executesql, if only Exec is not available. Record: -------------------------------------- Create Procedure dbo.t_sendtohigher@tablename varchar (255), @ itemcontent varchar (50), @ itemflag char (1) / * Insert uploaded data to the table * / askECLARE @SQL nvarchar (255) Declare @flag nchar (1)
Set @ SQL = N'SELECT @ flag = itemflag from ' @ Tablename ' Where itemid = ' @ iTemID ' EXEC SP_EXECUTESQL @ SQL, N '@ flag nchar (1) OUT', @ flag Out
/ * If the upload data is not on the upper server, the insertion operation * / if (@flag = null) beginset @ SQL = "INSERT INTO" @ Tablename "VALUES ('" @ ipemid "" " @ ItemContent "','" @ ipemflag ")" EXEC (@SQL) end / * If the upload data already exists, but no modification, execute update operation * / if (@flag = '0') beginset @ SQL = "Update" @ Tablename "set itemcontent =" @ itemcontent ", itemflag = '0' where itemid =" @ temidexec (@SQL) endGO
-------------------------------------------------- -------------------------------------------------- ----------------------------
This is a simple use of a bit of cursor: create procedure trans_synctableuploadState / * Check the data that you need to upload in the table you need to upload. In the publicinfo table, it is changed to the NULL PUBLICINFO table in the publicinfo table: UPLOADSTATE is NULL indicates that there is a data in the table that needs to upload uploadState to indicate that there is no data in the change in the publicinfo table in the PUBLICINFO table. UPLOADINFO field in the uploaded table: UPLOADSTATE When the data needs to upload UPLoadInfostate to 1 indicate that the strip does not need to upload * / askECLARE @Tablename varchar (50) Declare @sql nvarchar (200) Declare @isneedtotrans char 1) declare TableName_Cursor cursor for select SmallClassName from PublicInfo where BigClassNo = 18open TableName_Cursorfetch next from TableName_Cursor into @TableNamewhile @@ fetch_Status = 0beginset @ Sql = N'select @ IsNeedToTrans = count (*) from ' @ TableName ' where upload_state is null ' EXEC SP_EXECUTESQL @ SQL, N '@ isneedtotrans Char (1) Out', @ isneedtotrans Out
if (@IsNeedToTrans! = '0') beginupdate PublicInfo set upload_State = null where current of TableName_Cursorendelse if (@IsNeedToTrans = '0') beginupdate PublicInfo set upload_State = 1 where current of TableName_Cursorend
Fetch next from tablename_cursor @tablename_cursorDeallocate Tablename_cursorgo