473,320 Members | 1,828 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,320 software developers and data experts.

error while executing stored procedure

hi there
i have written follwing SP
to add two columns in my table (passing tablename as parameter)

create procedure sp_addCol
@tablename varchar (50)
as
DECLARE @tsql_TZ varchar (200)
SET @tsql_TZ = 'ALTER TABLE [ '+@tablename+'] ADD timezone varchar (5)'
DECLARE @tsql_EXP varchar (200)
EXEC(@tsql_TZ)
SET @tsql_EXP = 'ALTER TABLE [ '+@tablename+'] ADD exported varchar (5)'
EXEC(@tsql_EXP)

when i try to execute the SP
using following command

execute sp_addCol 'MGV10SEP_MNPC_MNLD'

it show me the error
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table ' MGV10SEP_MNPC_MNLD' because this table does not exist in database 'SIL_TESTDB'.
Server: Msg 4902, Level 16, State 1, Line 1
Cannot alter table ' MGV10SEP_MNPC_MNLD' because this table does not exist in database 'SIL_TESTDB'.

but table is actually exist in database
please help

thanks & regards
Sep 16 '08 #1
2 2162
deepuv04
227 Expert 100+
Hi,
In the following two statements there is an extra space at the tablename.

SET @tsql_TZ = 'ALTER TABLE [ '+@tablename+'] ADD timezone varchar (5)'
SET @tsql_EXP = 'ALTER TABLE [ '+@tablename+'] ADD exported varchar (5)'


When the string is created an extra space is added to the name of the table which is not there. Remove the space and try again.

try this code
Expand|Select|Wrap|Line Numbers
  1. create procedure sp_addCol
  2. @tablename varchar (50)
  3. as
  4. DECLARE @tsql_TZ varchar (200)
  5. SET @tsql_TZ = 'ALTER TABLE ['+@tablename+'] ADD timezone varchar (5)'
  6. DECLARE @tsql_EXP varchar (200)
  7. EXEC(@tsql_TZ)
  8. SET @tsql_EXP = 'ALTER TABLE ['+@tablename+'] ADD exported varchar (5)'
  9. EXEC(@tsql_EXP)
  10.  
  11.  
Thanks
Sep 17 '08 #2
Hi,
In the following two statements there is an extra space at the tablename.

SET @tsql_TZ = 'ALTER TABLE [ '+@tablename+'] ADD timezone varchar (5)'
SET @tsql_EXP = 'ALTER TABLE [ '+@tablename+'] ADD exported varchar (5)'


When the string is created an extra space is added to the name of the table which is not there. Remove the space and try again.

try this code
Expand|Select|Wrap|Line Numbers
  1. create procedure sp_addCol
  2. @tablename varchar (50)
  3. as
  4. DECLARE @tsql_TZ varchar (200)
  5. SET @tsql_TZ = 'ALTER TABLE ['+@tablename+'] ADD timezone varchar (5)'
  6. DECLARE @tsql_EXP varchar (200)
  7. EXEC(@tsql_TZ)
  8. SET @tsql_EXP = 'ALTER TABLE ['+@tablename+'] ADD exported varchar (5)'
  9. EXEC(@tsql_EXP)
  10.  
  11.  
Thanks




oh!!!!!
thanks 4 ur reply :-)
Sep 17 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: shyner | last post by:
Hi Everyone, I've been battling this for two days with no luck. I'm using SQL Server 2000. Here's the mystery: I've got a stored procedure that takes a single varchar parameter to determine...
9
by: dtwilliams | last post by:
OK, i'm trying to do some error checking on stored procedures and am following the advise in Erland Sommarskog's 'Implementing Error Handling with Stored Procedures' document. Can anybody help...
0
by: Rhino | last post by:
I've written several Java stored procedures now (DB2 V7.2) and I'd like to write down a few "best practices" for reference so that I will have them handy for future development. Would the...
0
by: vaishaliekhar | last post by:
Hello, I have created a stored procedure using SPUFI. The stored procedure is defined to execute an external Assembler routine. There was no error while creating the stored procedure. While...
1
by: rvdw | last post by:
Hi All, I've a serious problem with executing stored procedures (SQL2000) from an Access db (version 97). After executing a stored procedure , msaccess hangs. The whole call to the procedure is...
3
by: Goog79 | last post by:
Hi everyone, first time here, so I'm sorry if this has been covered already ages ago. :( I am trying to learn T-SQL and Stored Procedures and bought the book on these topics by Djan...
3
by: Mike P | last post by:
I am repeatedly getting the error message 'error converting datatype varchar to bit'. I am passing a varchar variable to a stored procedure (where it is also a varchar) and then trying to write it...
4
by: vivsriaus | last post by:
I get this error: Line 1: Incorrect syntax near '.' when executing my stored procedure: ALTER PROCEDURE Test ( @Func VarChar(100) )
1
by: preejith | last post by:
Error Code : 1329, No data - zero rows fetched, selected, or processed. MYSQL I am getting the following error while running a stored procedure in mysql5.0 Error Code : 1329 No data - zero rows...
2
by: Gatsu | last post by:
Hello, have you suggest about this event? Thanks! JD Event Type: Warning Event Source: ASP.NET 2.0.50727.0 Event Category: Web Event Event ID: 1309 Event code: 3005 Event message: An...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.