1

我有一个名为 procedure look up 的表,它存储医疗程序,并且有多个公司表,我必须为其计算程序费用,因此我为它创建了一个动态查询

下面是查询

declare @TableProviderName  varchar(500)
,@SQLQuery1 nvarchar(max)
,@MaxRecordSize Int
,@Name varchar(250) = null    
,@code varchar(50)  = null
set @Name = 'sug'
set @TableProviderName = 'PRD_Tata_Details'
set @MaxRecordSize = 50

set @SQLQuery1 = '
;WITH CTE_Procedure AS 
(
select top (@MaxRecordSize1)
GPL_ID_PK   as  ProcedureID
,GPL_ProcedureType as   ProcedureType
,GPL_Code   as  ProcedureCode
,coalesce(Name,GPL_Name,null)as Procedurename
,GPL_CurrencyType_FK    as  CurrencyType
,ISNULL(GPL_Description,''NIL'') as ProcedureDescription
,ISNULL(GPL_PatientInstruction,''NIL'')as PatientInstructions
,GPL_ProcedureCategory_FK as ProcedureCategory
,GPL_CategorySpecialization_FK as ProcedureSpecialization
,coalesce(PatientPayable,GPL_ProcedureFee,0) as PatientPayable
,0 as InsurancePayable
,0 as InsuranceDiscount
,1 as ProcedureCount
,0 as IndBillingStatus
,Case
when GeneralProcedureID is not null then ''Insurance Supported'' 
else ''Insurance not Supported''
end as InsuranceStatus
,ROW_NUMBER( ) OVER ( ORDER BY GPL_Name ASC) as RowNumber
from
dbo.PRD_GeneralProcedure_Lookup
left join '
+ @TableProviderName +  
' 
on
GeneralProcedureID = GPL_ID_PK 
where
GPL_ProcedureType = @ProcedureType1
and
(@Name1 is null or GPL_Name like %@Name1%)
and
(@code1 is null or GPL_Code like %@code1%) 
)

Select 
* 
from 
CTE_Procedure
'       

Execute sp_executesql  @SQLQuery1, N'@MaxRecordSize1 int, @ProcedureType1 tinyint,@Name1 varchar(250)
, @code varchar(50)' ,@MaxRecordSize1 = @MaxRecordSize, @ProcedureType1 = 1 , @Name1 = @Name, @code1 = @code

但是当执行错误时说“'@Name1'附近的语法不正确”

谁能帮我解决条件方面的问题

4

1 回答 1

2

我认为这可能与您的like陈述以及您传递参数的方式有关。

看看这个问题Parameters & Like statement

@Name1 = "'%yourvalue%'"
于 2013-08-25T10:54:18.387 回答