|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
sp_executesql syntax problem on SQL 2000I'm trying to work around the 4000 character limit w/ sp_executesql in SQL 2000 by breaking apart my query into two strings and passing them as parameters. To test this, I'm trying to make it work in a very simple case, using Query Analyzer. I have run into the following problem that I could use help with. The following works against my database: declare @SqlTxt nvarchar(2000) declare @AClause integer set @AClause = 9998 set @SqlTxt = N'SELECT LoopId FROM RegConfig WHERE MachineId = @AClause' execute sp_executesql @SqlTxt, N'@AClause integer', @AClause However, if I move my parameter @AClause over as the table name and make it an nvarchar as below, it fails: declare @SqlTxt nvarchar(2000) declare @AClause nvarchar(40) set @AClause = 'RegConfig' set @SqlTxt = N'SELECT LoopId FROM @AClause WHERE MachineId = 9998' execute sp_executesql @SqlTxt, N'@AClause varchar(40)', @AClause The error I get is: Server: Msg 137, Level 15, State 2, Line 1 Must declare the variable '@AClause'. Is this just a syntax issue I'm missing between integers and nvarchars? |
|||||||||||||||||||||||