Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 executeSql help

Author  Topic 

mariechristine
Starting Member

27 Posts

Posted - 2004-07-12 : 05:14:30
I have variable of type table and the insert statement is using sp_executeSQl. The following is my code. HOwever it's giving me that i should declare @tblSendCont Variable even though i have. What's wrong???

Code:

declare @nSQL nvarchar(2000), @tableName nvarchar(50), @deptid int
declare @tblSendCont table(SendContDate datetime, ControllerID int,
ControllerName nvarchar(50), RegionID int)

set @nSQL = '
Insert into @tbl
select TS.SendCont_Date, TSC.Controller_ID, C.Controller_Name, TS.Region_ID

from SendContPrice TS
inner join SendContPRiceControllers TSC on TS.SendCont_ID=TSC.SendCont_ID
inner join Controller C on C.Controller_ID= TSC.Controller_ID
inner join ContDept CD on C.Controller_ID = CD.Controller_ID
where CD.Department_ID= ' + @deptID

exec sp_executeSQL @nSQL,
N'@tbl table(SendContDate datetime, ControllerID int,ControllerName nvarchar(50), RegionID int)', @tbl =@tblSendCont

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2004-07-12 : 07:12:38
You're going down the route of "dynamic sql"....but you haven't got the structure right...search here for examples of this type of code....


I think that you may have to change the following.

set @nSQL = 'Insert into' + @tbl + ' select TS.SendCont_Date, TSC.Controller_ID, C.Controller_Name, TS.Region_ID'
and then just run
exec sp_executeSQL @nSQL
Go to Top of Page
   

- Advertisement -