在动态表中插入数据

时间:2017-11-13 13:14:53

标签: sql sql-server sql-server-2008

我知道这个但是得到错误可以提供解决方案。

marker.setTitle('hii')

2 个答案:

答案 0 :(得分:1)

你没有创建表,它应该看起来像这样

DECLARE @TableName VARCHAR(500);

SET @TableName = N'businessmaster_'+CONVERT(VARCHAR(10),GetDate()-1,112);

EXEC (N'CREATE TABLE '+@TableName +' ( contentid int,Businessname varchar(50) )')

print @TableName
declare  @sql varchar(100)    

SET @sql = 'INSERT INTO '+ @TableName+' (contentid,Businessname) SELECT top 10 contentid,Businessname FROM businessmaster';
EXEC (@sql)

答案 1 :(得分:1)

您没有创建表,如何向表中插入数据不存在:

DECLARE @TableName VARCHAR(MAX);
DECLARE @SQL NVARCHAR(MAX);
SET @TableName = N'businessmaster_'+
                 CONVERT(VARCHAR(10),GetDate()-1,112);

SET @SQL = N' CREATE TABLE '+@TableName + N' ( contentid int,Businessname varchar(50) )';

EXECUTE (@SQL);

SET @SQL = 'INSERT INTO '+ @TableName+' (contentid,Businessname) SELECT top 10 contentid,Businessname FROM businessmaster';

EXECUTE (@SQL);

<强> Demo