Solved

Dynamics SQL Script with alphanumeric variables

Posted on 2007-12-03
1
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

623 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