Note that there are some explanatory texts on larger screens.

plurals
  1. PODyanamic SQL Query not working
    primarykey
    data
    text
    <p>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 </p> <p>below is the query</p> <pre><code>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 </code></pre> <p>but when executing error occurs saying "Incorrect syntax near '@Name1'"</p> <p>can anyone help me with that where condition side issue</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload