473,385 Members | 1,267 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Sp_executesql Silly Error

Bkr
Gurus,

Here is what I ma trying to do. I have numeric expression stored in a
table column. for e.g. @a + @b + @c. I supply values to the variables
at run time and want them to be computed at run time as per the
expression in the column.
the stored procedure works fine but it gives a silly error.

Any help greatly appreciated. Below is the code.

--drop procedure proc_bkr
create procedure proc_bkr AS

declare @expr nvarchar(2000)
declare @sql nvarchar(2000)
declare @temp_exp nvarchar(3000)
declare @ans integer

declare @QFAAPAC02_1 integer
declare @QFAAPAC02_2 integer
declare @QFAAPAC02_3 integer
declare @QFAAPAC02_4 integer

-- Assigning values to variables -- Start
set @QFAAPAC02_1 = (Select QFAAPAC02_1 from fa_ap_stage where recordid
= 3)
set @QFAAPAC02_2 = (Select QFAAPAC02_2 from fa_ap_stage where recordid
= 3)
set @QFAAPAC02_3 = (Select QFAAPAC02_3 from fa_ap_stage where recordid
= 3)
set @QFAAPAC02_4 = (Select QFAAPAC02_4 from fa_ap_stage where recordid
= 3)
-- Assigning values to variables -- End
set @temp_exp = (select num from translation where processid = 'AP' and
label = 'C1')
-- This is how num looks: @QFAAPAC02_1 + @QFAAPAC02_2 + @QFAAPAC02_3 +
@QFAAPAC02_4

--select @expr = '@QFAAPAC02_1 + @QFAAPAC02_2 + @QFAAPAC02_3 +
@QFAAPAC02_4'
-- Above line works fine but below one does not. though both are same.

select @expr = @temp_exp
select @sql = 'select @ans = ' + @expr

exec sp_executesql @sql, N'@QFAAPAC02_1 integer, @QFAAPAC02_2 integer,
@QFAAPAC02_3 integer, @QFAAPAC02_4 integer, @ans integer OUTPUT',
@QFAAPAC02_1,@QFAAPAC02_2,@QFAAPAC02_3,@QFAAPAC02_ 4,@ans OUTPUT

set @cc = @ans
Error Message: Server: Msg 137, Level 15, State 2, Line 1
[Microsoft][ODBC SQL Server Driver][SQL Server]Must declare the
variable '@QFAAPAC02_'.
Thanks in Advance!

Bkr

Jul 23 '05 #1
1 1479
Bkr
Got the error folks. The record in the table had a space between 02_
and 4. Code works fine now.

Thanks!

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Justin Wong | last post by:
CREATE PROCEDURE dbo.Synchronization_GetNewRecords ( @item varchar(50), @last datetime ) AS SET NOCOUNT ON
7
by: LineVoltageHalogen | last post by:
Greetings All, I have a very large query that uses dynamic sql. The sql is very large and it requires it to be broken into three components to avoid the nvarchar(4000) issue: SET @v_SqlString(...
1
by: Matik | last post by:
Hi to all, Probably I'm just doing something stupid, but I would like you to tell me that (if it is so), and point the solution. There ist the thing: I' having a sp, where I call other sp...
1
by: satishchandrat | last post by:
Hi, This is regarding the sp_executesql and the sql statement parameter, in processing a dynamic SQL on SQL Server 2000, in my stored procedure. I have my SQL string exeeding more than 4000...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.