質問

I have a table called procedure look up which stores medical procedures and have multiple company table for which i had to calculate the procedure fees so i had created a dynamic query for it

below is the query

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

but when executing error occurs saying "Incorrect syntax near '@Name1'"

can anyone help me with that where condition side issue

役に立ちましたか?

解決

I think It may have something to do with your like statement and the way you pass the parameter.

Have a look at this question Parameters & Like statement.

@Name1 = "'%yourvalue%'"
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top