定义变量存放表的列名:
@SQL_INSERTSYU_MAI nvarchar(4000)
set @SQL_INSERTSYU_MAI = ' '
set @SQL_INSERTSYU_MAI = @SQL_INSERTSYU_MAI + 'KEIJ_NEN ,KEIJ_KI ,WEEK_YMD ,BJ_NO ,SEQ_NO '
执行下面语句时报列名无效的错误,应该怎么写?
INSERT INTO M_BCMEISAI_SYU ( @SQL_INSERTSYU_MAI )
VALUES ( ..... )
谢谢
------解决方案--------------------
exec( 'INSERT INTO M_BCMEISAI_SYU ( '+ @SQL_INSERTSYU_MAI + ')
VALUES ( ..... ) ')
------解决方案--------------------
exec( 'INSERT INTO M_BCMEISAI_SYU ( '[email protected]_INSERTSYU_MAI+ ') VALUES ( ' 'A ' ', ' 'B ' '... )
')
------解决方案--------------------
declare @sql varchar(8000)
set @sql= 'INSERT INTO M_BCMEISAI_SYU ( '[email protected]_INSERTSYU_MAI+ ' ) VALUES ( ..... ) '
exec(@sql)