我正在尝试在 SQL Server 2005 中执行以下过程。我能够在我的开发服务器中执行它,当我尝试在 Live Server 中使用它时,我收到错误“内部查询处理器错误:查询处理器无法生成查询计划。有关详细信息,请联系客户支持服务”。我使用相同的数据库和相同的格式。当我们在网上搜索时,它显示了一些要在 sql server 2005 中使用的修复程序以避免此错误,但我的 DBA 已确认所有补丁程序都已在我们的服务器中更新。谁能给我一些线索。
询问:
create Procedure [dbo].[sample_Select]
@ID as varchar(40)
as
Declare @Execstring as varchar(1000)
set @Execstring =
'
Declare @MID as varchar(40)
Set @MID = '''+@ID+'''
select * from (
select t1.field1, t1.field2 AS field2 , t1.field3 AS field3 , L.field1 AS field1 , L. field2 AS field2 from table1 AS t1
INNER JOIN MasterTable AS L ON L. field1 = t1. field2
where t1. field2 LIKE @MID
) as DataTable
PIVOT
(
Count(field2)
FOR field3
IN ('
Select @Execstring=@Execstring+ L.field2 +',' FROM MasterTable AS L inner join
table1 AS t1 ON t1.field1= L.field2 Where t1.field2 LIKE @ID
set @Execstring = stuff(@Execstring, len(@Execstring), 1, '')
set @Execstring =@Execstring +')) as pivotTable'
exec (@Execstring)