Syntax error converting the nvarchar value 'INSERT INTO....
-
Hi All, I am getting the following error, Msg 245, Level 16, State 1, Line 13 Syntax error converting the nvarchar value 'INSERT INTO [mydb].[dbo].[temp] ( [f1], [f2], [f3], [f4] ) VALUES( 222, 333, 44, ' to a column of data type int. while executing the below code DECLARE @t_f1 as int DECLARE @t_f2 as nvarchar(50) DECLARE @t_f3 as nvarchar(50) DECLARE @t_f4 as nvarchar(50) set @t_f1 = 111 set @t_f2 = 222 set @t_f3e = 333 set @t_f4 = 44 declare @q as nvarchar(500) set @q = 'INSERT INTO [mydb].[dbo].[temp] ( [fld1], [fld2], [fld3], [fld4] ) VALUES( '+@t_f1+', '+@t_f2+', '+@t_f3+', '+@t_f4+' )' exec @q My database table structure is as follows, CREATE TABLE temp ( fld1 int, fld2 nvarchar(50), fld3 nvarchar(20), fld4 nvarchar(20), ) Thanks in advance... ~Mahantesh V H
-
Hi All, I am getting the following error, Msg 245, Level 16, State 1, Line 13 Syntax error converting the nvarchar value 'INSERT INTO [mydb].[dbo].[temp] ( [f1], [f2], [f3], [f4] ) VALUES( 222, 333, 44, ' to a column of data type int. while executing the below code DECLARE @t_f1 as int DECLARE @t_f2 as nvarchar(50) DECLARE @t_f3 as nvarchar(50) DECLARE @t_f4 as nvarchar(50) set @t_f1 = 111 set @t_f2 = 222 set @t_f3e = 333 set @t_f4 = 44 declare @q as nvarchar(500) set @q = 'INSERT INTO [mydb].[dbo].[temp] ( [fld1], [fld2], [fld3], [fld4] ) VALUES( '+@t_f1+', '+@t_f2+', '+@t_f3+', '+@t_f4+' )' exec @q My database table structure is as follows, CREATE TABLE temp ( fld1 int, fld2 nvarchar(50), fld3 nvarchar(20), fld4 nvarchar(20), ) Thanks in advance... ~Mahantesh V H
-
Hi!!!! Execute statement only takes nvarchar,char....datatype only so u change data type like DECLARE @t_f1 as nvarchar(50) DECLARE @t_f2 as nvarchar(50) DECLARE @t_f3 as nvarchar(50) DECLARE @t_f4 as nvarchar(50) Regards ;) Shashank
Is there any other alternative means for integer data type? ~Mahantesh V H
-
Is there any other alternative means for integer data type? ~Mahantesh V H
-
You probably can use the CONVERT() function to convert the int variable to nvarchar. Try
CONVERT(@t_f1 AS NVARCHAR(50))
Ed -
Anonymous wrote:
I want to insert int not char...
Yes, I know. But from what I see it seems that the SQL is complaining that you are adding the nvarchar 'INSERT INTO [mydb].[dbo].[temp]..' into @t_f1 (which is an integer) when concatenating the @q. The convert is just to make sure your @q can be created by concatenating nvarchars instead of adding it to an int. When you execute it it should insert an integer instead of an nvarchar. Btw, why are you using exec @q anyway? You don't seem to need to create a dynamic SQL statement for that one. Ed