Solved

Dynamics SQL Script with alphanumeric variables

Posted on 2007-12-03
1
217 Views
Last Modified: 2008-05-28
I have this stored procedure. As long as the variable sent down is a number it works. However, if I send it an alphumeric value(i.e. C99 as opposed to 99) it errors out with the message "Invalid Column Name". How do I correct my stored procedure?


CREATE PROCEDURE [dbo].[rbsUpdateSTAXNOTE] 
@Old_CustomerID varchar(15),
@New_CustomerID varchar(15),
@Return_code int output
 
AS 
 
declare @sql nvarchar(4000)
SET @Return_Code = 1
/* If old customer ID is found, update it to the new customer ID */
IF EXISTS (SELECT * FROM STAXNOTE WHERE rtrim(CUSTOMER_NUMBER_STXN)=rtrim(@Old_CustomerID))
BEGIN
    
    SET @sql = ' update STAXNOTE ' +
               ' set CUSTOMER_NUMBER_STXN = ' + @New_CustomerID + 
               ' where CUSTOMER_NUMBER_STXN= @Old_CustomerID'
    exec sp_executesql @sql, N'@Old_CustomerID varchar(15)',@Old_CustomerID
  
END
ELSE
BEGIN
    SET @Return_Code=0
END
 
SELECT @Return_Code
 
RETURN 
 
GO

Open in new window

0
Comment
Question by:rwheeler23
1 Comment
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 20397613
rwheeler23 said:
>>               ' set CUSTOMER_NUMBER_STXN = ' + @New_CustomerID +

Change to:

               ' set CUSTOMER_NUMBER_STXN = ''' + @New_CustomerID + '''' +

Note that those are all single-quotes...
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get the latest status 8 32
Help in Bulk Insert 9 35
sql server service accounts 4 26
SQL Query assistance 16 26
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question