Hello all,

I'm attempting to create a stored procedure in sql server 7.  It would check if the 
page already exists within a table and if so increment the proper column (pages would 
have a column for each month of the year) else it would do an insert statement.  My 
problem is that It won't allow for dynamic column names within the set statement 
assignments (possibly a syntax error).  The error I receive is:

 [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the nvarchar 
value 'August' to a column of data type int.

The variable @CurrentMonth returns the name of the month which is also the column name 
(January, March, July etc) in the table and @thePage is the name of the page.  Each 
column is a data type of integer.

CREATE PROCEDURE spCounter
 (
 @thePage NVARCHAR(100),
 @CurrentMonth NVARCHAR(100)
  )
AS
 if NOT EXISTS (SELECT * FROM Counter WHERE Page = @thePage)
  begin
   INSERT INTO Counter (Page)
   VALUES (@thePage);

   UPDATE Counter
   SET @CurrentMonth = @CurrentMonth+1 
   WHERE Page = @thePage;
   end
 else
  UPDATE Counter
  SET @CurrentMonth = @CurrentMonth+1 
  WHERE Page = @thePage

Does anyone have a more efficient way of doing this or understand what's going wrong 
in that code.

Thanks in advance for your help,

-Kevin


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to