![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
EXEC sp_executesql @cmd, @tbl, @id, @week |
#3
| |||
| |||
|
|
I am trying to set up a procedure that takes the table name as one of the parameters and then executes an update statement for the specified criteria. I am getting Msg 102 errors, Incorrect syntax near table name, id and week. Does anybody know what the problem is? Thanks for your help! CREATE PROCEDURE [dbo].[change] @id nvarchar(10), @week nvarchar(10),@tbl nvarchar(10) AS BEGIN DECLARE @strsql as nvarchar(500) SET @strsql = N'UPDATE ' + @tbl + N' SET [status] = 3 WHERE ID = ' + @id + N' and [WEEK] = ' + @week EXEC sp_executesql @cmd, @tbl, @id, @week END |
#4
| |||
| |||
|
|
EXEC sp_executesql @cmd, @tbl, @id, @week Yes, @cmd is not defined in your stored procedure. -Eric Isaacs |
#5
| |||
| |||
|
|
Maybe you meant: EXEC sp_executesql @strsql; On 8/25/09 3:40 PM, in article OLGSivbJKHA.3632 (AT) TK2MSFTNGP05 (DOT) phx.gbl, "Galla" <private (AT) somedomain (DOT) com> wrote: I am trying to set up a procedure that takes the table name as one of the parameters and then executes an update statement for the specified criteria. I am getting Msg 102 errors, Incorrect syntax near table name, id and week. Does anybody know what the problem is? Thanks for your help! CREATE PROCEDURE [dbo].[change] @id nvarchar(10), @week nvarchar(10),@tbl nvarchar(10) AS BEGIN DECLARE @strsql as nvarchar(500) SET @strsql = N'UPDATE ' + @tbl + N' SET [status] = 3 WHERE ID = ' + @id + N' and [WEEK] = ' + @week EXEC sp_executesql @cmd, @tbl, @id, @week END |
#6
| |||
| |||
|
|
Ah yes, thanks Aaron, that did it ... plus another little tweak for the id and week parameters: SET @strsql= N'UPDATE ' + @tbl + N' SET [status] = 3 WHERE ID = ''' + @id + N''' and [WEEK] = ''' + @week + '''' EXEC sp_executesql @strsql |
#7
| |||
| |||
|
|
I am trying to set up a procedure that takes the table name as one of the parameters and then executes an update statement for the specified criteria. I am getting Msg 102 errors, Incorrect syntax near table name, id and week. Does anybody know what the problem is? Thanks for your help! CREATE PROCEDURE [dbo].[change] @id nvarchar(10), @week nvarchar(10),@tbl nvarchar(10) AS BEGIN DECLARE @strsql as nvarchar(500) SET @strsql = N'UPDATE ' + @tbl + N' SET [status] = 3 WHERE ID = ' + @id + N' and [WEEK] = ' + @week EXEC sp_executesql @cmd, @tbl, @id, @week |
![]() |
| Thread Tools | |
| Display Modes | |
| |