Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: dynamic INSERT stmt in stored proc SQL2000


Message #1 by "lisa smith" <lisa@m...> on Tue, 18 Jun 2002 19:56:30
sorry to have doubted you :) Thank you for your help, it worked!

-----Original Message-----
From: Denis Gobo [mailto:dgobo@w...]
Sent: Tuesday, June 18, 2002 11:54 AM
To: sql language
Subject: [sql_language] RE: dynamic INSERT stmt in stored proc SQL2000


Since you are constructing a string you need to convert the all int
values to a string
Like this CONVERT(varchar(4),@CustomerID )

-----Original Message-----
From: lisa smith [mailto:lisa@m...]
Sent: Tuesday, June 18, 2002 3:57 PM
To: sql language
Subject: [sql_language] dynamic INSERT stmt in stored proc SQL2000


I am trying to use variable names for columns on an INSERT stmt in a
stored procedure.  I have concatenated the variables to the insert
string
and set it to a variable declared as a varchar(1000).  I keep getting
the
error:

"error converting the varchar value 'INSERT INTO Totals (CustomerID,
StarterKits,Season4Kits,PromoCards4,Stickers4,Playmats4,Folders,
Tshirts,
Stampers, WindowClings) VALUES ('... to a column of data type int."

even though the variable I am setting that string to is not an integer.

Does anyone know what would cause this?

Here is the code I used for concatenation inside the stored procedure:

SET @stmt = 'INSERT INTO Totals (CustomerID, StarterKits,' +
@SeasonXkits
+ ',' +  @PromoCardsX + ',' +  @StickersX + ',' +  @PlaymatsX + ','
+ 'Folders, Tshirts, Stampers, WindowClings) VALUES (' + @CustomerID +
','
+ @tStarterKits + ',' + @tSeasonKits + ',' + @tPromoCards + ',' +
@tStickers + ',' + @tPlaymats + ',' + @tFolders + ',' + @tTshirts + ','
+
@tStampers + ',' + @tWindowClings + ')'
EXEC(@stmt)

The variables with X in them are strings and the rest are integers.  I
had
thought that the string variables might need two extra ' to show them as

strings when concatenating, but I still got the same error. And the
string
displayed in the error put 's around the names.

Does anyone know of any other way to use variable names as columns to be

updated in an INSERT statment?

Thanks,

Lisa



  Return to Index