本文介绍了如何使这项工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前我已经开始创建一个过程,该过程获取参数,并且应该在一定条件下将一个表的内容复制到另一个表。我在这里复制了代码。它编译好。但没有任何影响。
Currently I have started creating a procedure, which gets the parameters and should copy the contents of one table to another with certain conditions. I have copied the codes here. It compiles good. But nothing is affected.
ALTER PROCEDURE sp_ArchiveTable1(
@StartDate datetime,
@EndDate datetime,
@DateColumn VARCHAR(100),
@TableName VARCHAR(100),
@NewTableName VARCHAR(100)
)
AS
DECLARE @NextIDs TABLE(UniqueID int primary key)
SELECT * INTO [@NewTableName] FROM [@TableName]
WHERE [@DateColumn] >= @StartDate AND [@DateColumn] <= @EndDate
推荐答案
ALTER PROCEDURE sp_ArchiveTable1(
@StartDate datetime,
@EndDate datetime,
@DateColumn VARCHAR(100),
@TableName VARCHAR(100),
@NewTableName VARCHAR(100)
)
AS
BEGIN
DECLARE @NextIDs TABLE(UniqueID int primary key)
DECLARE @statement nchar(1000) = N'SELECT * INTO '+@NewTableName+' FROM '+@TableName+'
WHERE '+@DateColumn+' BETWEEN '''+CONVERT(VARCHAR(100), @StartDate)+''' AND '''+CONVERT(VARCHAR(100), @EndDate)+''''
PRINT @statement
EXEC sys.sp_ExecuteSQL @statement
END
go
但是你必须要小心 [ ]。
请参阅 []
But you''ll have to be careful about SQL injection[^].
See SQL Injection: What is it?[^]
这篇关于如何使这项工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!