I am trying to write a simple SP by building dynamic queries and storing in a variable and executing the variable.
I currently get the following error:
Msg 206, Level 16, State 2, Line 16
Operand type clash: datetime2 is incompatible with float
For the following code:
DECLARE
@table_Num
@1 varchar(100) = 'boo',
@2 int =2,
@3 varchar(100) ='default',
@4 varchar(50) = NULL,
@5 int =NULL,
@6 float =12,
@7 datetime2(0) ='1970-01-01 00:00:00',
@8 datetime2(0)='1970-01-01 00:00:00',
@9 varchar(50)='',
@10 varchar(50)=NULL,
@11 decimal(18,0)=0000000000000,
@12 int =999999
DECLARE @SQLString NVARCHAR(MAX)
SET @SQLString = 'INSERT INTO abc_'+@table_Num+'(col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12)
VALUES ('+@1+',2,'+@3+','+@4+','+@5+','+@6+','+@7+','+@8+','+@9+','+@10+','+@11+','+@12+')'
EXEC (@SQLString)
As far as I can see the variables are same type as table col types. Any ideas?
table_1as well please?