Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with EXEC String Please 1

Status
Not open for further replies.

shiggyshag

Programmer
Dec 14, 2001
227
GB
HI Im using the below

ALTER PROCEDURE dbo.StoredProcedure1
(@SiteID int,
@PlotNumber int)
AS

Declare @tablename VarChar(50)
Declare @SQLCommand VarChar(200)

set @tablename = (SELECT TableName FROM dbo.tSite WHERE (SiteID = @SiteID))

SET @SQLCommand = 'UPDATE dbo.' + rtrim(@tablename) + ' SET Status = N''Hold'' WHERE (dbo.PlotNumber =' + @PlotNumber + ')'

EXEC(@SQLCommand)


and the result is

Syntax error converting the varchar value 'UPDATE dbo.tNewark SET Status = N'Hold' WHERE (dbo.PlotNumber =' to a column of data type int.


What is casuing this problem?

Any Help would be great
 
Just a little syntax error. Remove the single quotes around the @PlotNumber

Code:
SET @SQLCommand = 'UPDATE dbo.' + rtrim(@tablename) + ' SET Status = N''Hold'' WHERE (dbo.PlotNumber = + @PlotNumber + )'

Patrick
 
Hi Thank you but now im getting

Must declare the variable '@PlotNumber'.

Cheers
 
Try converting your @PlotNumber (in your original script) to a varchar using the convert function.
I've had similar problems and I think it's caused when you use the plus sign with an int - it doesn't know whether to concatenate or add!
Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top