2016-01-23 226 views
0

這裏是我的存儲過程,我不知道它在哪裏引起錯誤?請幫助我....提前致謝。System.Data.SqlClient.SqlException:'in'附近的語法不正確

這些是我嵌入到存儲過程的代碼線和這些語句包含「IN」關鍵字

Declare @SQLQuery Nvarchar(1000) 



     set @SQLQuery = ' select distinct program from tblProgNotes where Program in ' + @Program 

     --print @SQLQuery 
     create TABLE #T1 (Program int) 
     insert into #T1 execute sp_executesql @SQLQuery 

和(@Program爲空或從#T1中(選擇程序(P.Program) )) 最後一行被嵌入在給定存儲過程##

三個地方和(@Program爲空或(在(從#T1選擇程序P.Program))) 該線被嵌入在三個時間給定存儲過程:我不知道它在哪裏造成錯誤。

  @StartDate DateTime, 
      @EndDate DateTime, 
      @ShowDollars bit = 0, 
      @LateEntryOnly bit = 0, -- new 
      @Status int = null, -- value of dropdown be locationid 
      @Program nvarchar = null, -- value of dropdown be lookup codeID 
      @Clinician int = null, -- value of tblProviders UserID 
      @Billable int = 0 

     As 

     Declare @SQLQuery Nvarchar(1000) 



     set @SQLQuery = ' select distinct program from tblProgNotes where Program in ' + @Program 

     --print @SQLQuery 
     create TABLE #T1 (Program int) 
     insert into #T1 execute sp_executesql @SQLQuery 



     select B.ID as BillingCodeID, Code, B.MOD1, B.MOD2, RateAmount, StartDate, EndDate, POS, LicenseGroupID, Billable,ProviderID 
     into #tmpRates 
     from tblRates R 
     left join tblBillingCodes B on B.ID = R.BillingCodeID 
     where PayorID = 1 


     if @ShowDollars = 1 
     Begin 
     select distinct 
     Isnull(U.LastName,'') + ', ' + IsNull(U.Firstname,'') as Clinician, 
     p.DateOfService, 
     P.PaceID, 
     Dem.LastName + ', ' + Dem.FirstName as ClientName, 
     P.ID as ProgressNoteID, 
     PC.BillingCodeID, 
     PC.ProgressNoteType, 
     BC.Code, 
     PC.POS, 
     BC.MOD1, 
     BC.MOD2, 
     Isnull(BC.Code,'') + ' ' + ISnull(PC.POS,'') + ' ' + ISNULL(BC.MOD1,'') + ' ' + ISNULL(BC.MOD2,'') as FullHCPC, 
     PC.Units, 
     PC.TimeIn, 
     PC.TimeOut, 
     DateDiff(mi,PC.TimeIn, PC.TimeOut) as Minutes, 
     Case when Datediff(mi,PC.TimeIn,PC.TimeOut)/60 > 0 
     then Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut)/60) + 'h ' + Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut) % 60) + 'm' else Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut) % 60) + 'm' end as TimeDesc, 
     I.BehavioralHealthCategory, 
     case when p.DateOfService > '8/1/13' and PC.BillingCodeID in (3,4) and PC.DOCID is null then 'Log Missing' else convert(varchar(20),PC.DocID) end as TransportationLog, 
     L3.Description as Program, 
     P.LateEntry, 
     case when PC.Billable = 0 then 'Non Billable' else '' end as NonBillable, 
     (Convert(float,IsNull(R.RateAmount,0)) * case when PC.Units ='' then 0 else Convert(float,PC.Units) end) as 'Service Value', 
     a.currentlocation as Status 
     from tblProgNotes P 
     left join tblProgressNoteCodes PC on PC.ProgressNoteID = P.ID and PC.ProgressNoteType = 1 
     left join tblLicensure L on L.ProviderID = P.ClinicianID and L.[Primary] = 1 and P.DateOfService >= L.StartDate and (L.EndDate is null or L.EndDate >= P.DateOfService) 
     left join tblLookups L2 on L2.Code = L.LicenseTypeID and L2.CategoryID = 48 
     left join tblLookups L3 on L3.Code = P.Program and L3.CategoryID = 104 
     left join #tmpRates R on R.BillingCodeID = PC.BillingCodeID and R.POS = PC.POS and R.LicenseGroupID = L2.Type and R.Billable = PC.Billable and R.ProviderID = P.Site 
      and R.StartDate <= p.DateOfService and R.EndDate >= p.DateOfService 
     left join tblBillingCodes BC on BC.ID = PC.BillingCodeID 
     left join tblDemographics Dem on Dem.PaceID = P.PaceID 
     left join tblIntakes I on I.ID = P.IntakeID 
     left join tblReferrals CR on CR.ID = I.ReferralID 
     left join tblProviders PP on PP.ID = P.ClinicianID 
     left join vwUsers U on U.ID = PP.UserID 
     left join tblactivities A on A.extid1 = P.paceid and A.extid2 = P.ID and A.completedDate is null and A.currentlocationid in (select locationid from tbllocations where workflowid = 4) and A.visible = 1 and A.extid4 = 1 
     where DateOfService >= @StartDate and DateOfService <= @EndDate 
     and P.Deleted = 0 
     and PC.Void = 0 
     and (@Status is null or (a.currentlocationID = @Status)) 
     and (@Program is null or (P.Program in (select program from #T1))) 
     and (@Clinician is null or (P.ClinicianUserID = @Clinician)) 
     and (@LateEntryOnly = 0 or (P.LateEntry = @LateEntryOnly)) 
     and ((@Billable =0) or (@Billable = 1 and PC.Billable = 1) or (@Billable = 2 and PC.Billable = 0)) 

     Union All 
     select distinct 
     Isnull(U.LastName,'') + ', ' + IsNull(U.Firstname,'') as Clinician, 
     convert(varchar(15),P.DateOfService,101) as DateOfService, 
     P.PaceID, 
     Dem.LastName + ', ' + Dem.FirstName as ClientName, 
     P.ID as ProgressNoteID, 
     PC.BillingCodeID, 
     PC.ProgressNoteType, 
     BC.Code, 
     PC.POS, 
     BC.MOD1, 
     BC.MOD2, 
     Isnull(BC.Code,'') + ' ' + ISnull(PC.POS,'') + ' ' + ISNULL(BC.MOD1,'') + ' ' + ISNULL(BC.MOD2,'') as FullHCPC, 
     PC.Units, 
     PC.TimeIn, 
     PC.TimeOut, 
     DateDiff(mi,pc.TimeIn,pc.TimeOut) as Minutes, 
     Case when Datediff(mi,PC.TimeIn,PC.TimeOut)/60 > 0 
     then Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut)/60) + 'h ' + Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut) % 60) + 'm' else Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut) % 60) + 'm' end as TimeDesc, 
     I.BehavioralHealthCategory, 
     case when p.DateOfService > '8/1/13' and PC.BillingCodeID in (3,4) and PC.DOCID is null then 'Log Missing' else convert(varchar(20),PC.DocID) end as TransportationLog, 
     L3.Description as Program, 
     P.LateEntry, 
     case when PC.Billable = 0 then 'Non Billable' else '' end as NonBillable, 
     (Convert(float,IsNull(R.RateAmount,0)) * case when PC.Units ='' then 0 else Convert(float,PC.Units) end) as 'Service Value', 
     a.currentlocation as Status 

     from tblCrisisProgressNotes P 
     left join tblProgressNoteCodes PC on PC.ProgressNoteID = P.ID and PC.ProgressNoteType = 2 
     left join tblLicensure L on L.ProviderID = P.ClinicianID and L.[Primary] = 1 and P.DateOfService >= L.StartDate and (L.EndDate is null or L.EndDate >= P.DateOfService) 
     left join tblLookups L2 on L2.Code = L.LicenseTypeID and L2.CategoryID = 48 
     left join tblLookups L3 on L3.Code = P.Program and L3.CategoryID = 104 
     left join #tmpRates R on R.BillingCodeID = PC.BillingCodeID and R.POS = PC.POS and R.LicenseGroupID = L2.Type and R.Billable = PC.Billable and R.ProviderID = P.Site 
      and R.StartDate <= p.DateOfService and R.EndDate >= p.DateOfService 
     left join tblBillingCodes BC on BC.ID = PC.BillingCodeID 
     left join tblDemographics Dem on Dem.PaceID = P.PaceID 
     left join tblIntakes I on I.ID = P.IntakeID 
     left join tblReferrals CR on CR.ID = I.ReferralID 
     left join tblProviders PP on PP.ID = P.ClinicianID 
     left join vwUsers U on U.ID = PP.UserID 
     left join tblactivities A on A.extid1 = P.paceid and A.extid2 = P.ID and A.completedDate is null and A.currentlocationid in (select locationid from tbllocations where workflowid = 4) and A.visible = 1 and A.extid4 = 2 
     where P.DateOfService >= @StartDate and P.DateOfService <= @EndDate 
     and P.Deleted = 0 
     and PC.Void = 0 
     and (@Status is null or (a.currentlocationID = @Status)) 
     and (@Program is null or (P.Program in (select program from #T1))) 
     and (@Clinician is null or (P.ClinicianUserID = @Clinician)) 
     and (@LateEntryOnly = 0 or (P.LateEntry = @LateEntryOnly)) 
     and ((@Billable =0) or (@Billable = 1 and PC.Billable = 1) or (@Billable = 2 and PC.Billable = 0)) 

     Union All 
     select distinct 
     Isnull(U.LastName,'') + ', ' + IsNull(U.Firstname,'') as Clinician, 
     convert(varchar(15),p.DateOfService,101) as DateOfService, 
     P.PaceID, 
     Dem.LastName + ', ' + Dem.FirstName as ClientName, 
     P.ID as ProgressNoteID, 
     PC.BillingCodeID, 
     PC.ProgressNoteType, 
     BC.Code, 
     PC.POS, 
     BC.MOD1, 
     BC.MOD2, 
     Isnull(BC.Code,'') + ' ' + ISnull(PC.POS,'') + ' ' + ISNULL(BC.MOD1,'') + ' ' + ISNULL(BC.MOD2,'') as FullHCPC, 
     PC.Units, 
     PC.TimeIn, 
     PC.TimeOut, 
     DateDiff(mi,pc.TimeIn,pc.TimeOut) as Minutes, 
     Case when Datediff(mi,PC.TimeIn,PC.TimeOut)/60 > 0 
     then Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut)/60) + 'h ' + Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut) % 60) + 'm' else Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut) % 60) + 'm' end as TimeDesc, 
     I.BehavioralHealthCategory, 
     case when p.DateOfService > '8/1/13' and PC.BillingCodeID in (3,4) and PC.DOCID is null then 'Log Missing' else convert(varchar(20),PC.DocID) end as TransportationLog, 
     L3.Description as Program, 
     P.LateEntry, 
     case when PC.Billable = 0 then 'Non Billable' else '' end as NonBillable, 
     (Convert(float,IsNull(R.RateAmount,0)) * Convert(float,PC.Units)) as 'Service Value', 
     a.currentlocation as Status 
     from tblPersonalProgressNotes P 
     left join tblProgressNoteCodes PC on PC.ProgressNoteID = P.ID and PC.ProgressNoteType = 3 
     left join tblLicensure L on L.ProviderID = P.ClinicianID and L.[Primary] = 1 and P.DateOfService >= L.StartDate and (L.EndDate is null or L.EndDate >= P.DateOfService) 
     left join tblLookups L2 on L2.Code = L.LicenseTypeID and L2.CategoryID = 48 
     left join tblLookups L3 on L3.Code = P.Program and L3.CategoryID = 104 
     left join #tmpRates R on R.BillingCodeID = PC.BillingCodeID and R.POS = PC.POS and R.LicenseGroupID = L2.Type and R.Billable = PC.Billable and R.ProviderID = P.Site 
      and R.StartDate <= p.DateOfService and R.EndDate >= p.DateOfService 
     left join tblBillingCodes BC on BC.ID = PC.BillingCodeID 
     left join tblDemographics Dem on Dem.PaceID = P.PaceID 
     left join tblIntakes I on I.ID = P.IntakeID 
     left join tblReferrals CR on CR.ID = I.ReferralID 
     left join tblProviders PP on PP.ID = P.ClinicianID 
     left join vwUsers U on U.ID = PP.UserID 
     left join tblactivities A on A.extid1 = P.paceid and A.extid2 = P.ID and A.completedDate is null and A.currentlocationid in (select locationid from tbllocations where workflowid = 4) and A.visible = 1 and A.extid4 = 3 
     where P.DateOfService >= @StartDate and P.DateOfService <= @EndDate 
     and P.Deleted = 0 
     and PC.Void = 0 
     and (@Status is null or (a.currentlocationID = @Status)) 
     and (@Program is null or (P.Program in (select Program from #T1))) 
     and (@Clinician is null or (P.ClinicianUserID = @Clinician)) 
     and (@LateEntryOnly = 0 or (P.LateEntry = @LateEntryOnly)) 
     and ((@Billable =0) or (@Billable = 1 and PC.Billable = 1) or (@Billable = 2 and PC.Billable = 0)) 
     order by Clinician, DateOfService,Code, POS, MOD1, MOD2 ,ClientName, TimeIn 

     END 
     Else 
     BEGIN 

     select distinct 
     Isnull(U.LastName,'') + ', ' + IsNull(U.Firstname,'') as Clinician, 
     convert(varchar(15),p.DateOfService,101) as DateOfService, 
     P.PaceID, 
     Dem.LastName + ', ' + Dem.FirstName as ClientName, 
     P.ID as ProgressNoteID, 
     PC.BillingCodeID, 
     PC.ProgressNoteType, 
     BC.Code, 
     PC.POS, 
     BC.MOD1, 
     BC.MOD2, 
     Isnull(BC.Code,'') + ' ' + ISnull(PC.POS,'') + ' ' + ISNULL(BC.MOD1,'') + ' ' + ISNULL(BC.MOD2,'') as FullHCPC, 
     PC.Units, 
     PC.TimeIn, 
     PC.TimeOut, 
     DateDiff(mi,PC.TimeIn, PC.TimeOut) as Minutes, 
     Case when Datediff(mi,PC.TimeIn,PC.TimeOut)/60 > 0 
     then Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut)/60) + 'h ' + Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut) % 60) + 'm' else Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut) % 60) + 'm' end as TimeDesc, 
     I.BehavioralHealthCategory, 
     case when p.DateOfService > '8/1/13' and PC.BillingCodeID in (3,4) and PC.DOCID is null then 'Log Missing' else convert(varchar(20),PC.DocID) end as TransportationLog, 
     L3.Description as Program, 
     P.LateEntry, 
     a.currentlocation as Status 
     from tblProgNotes P 
     left join tblProgressNoteCodes PC on PC.ProgressNoteID = P.ID and PC.ProgressNoteType = 1 
     left join tblLicensure L on L.ProviderID = P.ClinicianID and L.[Primary] = 1 and P.DateOfService >= L.StartDate and (L.EndDate is null or L.EndDate >= P.DateOfService) 
     left join tblLookups L2 on L2.Code = L.LicenseTypeID and L2.CategoryID = 48 
     left join tblLookups L3 on L3.Code = P.Program and L3.CategoryID = 104 
     left join #tmpRates R on R.BillingCodeID = PC.BillingCodeID and R.POS = PC.POS and R.LicenseGroupID = L2.Type and R.Billable = PC.Billable and R.ProviderID = P.Site 
      and R.StartDate <= p.DateOfService and R.EndDate >= p.DateOfService 
     left join tblBillingCodes BC on BC.ID = PC.BillingCodeID 
     left join tblDemographics Dem on Dem.PaceID = P.PaceID 
     left join tblIntakes I on I.ID = P.IntakeID 
     left join tblReferrals CR on CR.ID = I.ReferralID 
     left join tblProviders PP on PP.ID = P.ClinicianID 
     left join vwUsers U on U.ID = PP.UserID 
     left join tblactivities A on A.extid1 = P.paceid and A.extid2 = P.ID and A.completedDate is null and A.currentlocationid in (select locationid from tbllocations where workflowid = 4) and A.visible = 1 and A.extid4 = 1 
     where DateOfService >= @StartDate and DateOfService <= @EndDate 
     and P.Deleted = 0 
     and PC.Void = 0 
     and (@Status is null or (a.currentlocationID = @Status)) 
     and (@Program is null or (P.Program in (select program from #T1))) 
     and (@Clinician is null or (P.ClinicianUserID = @Clinician)) 
     and (@LateEntryOnly = 0 or (P.LateEntry = @LateEntryOnly)) 
     and ((@Billable =0) or (@Billable = 1 and PC.Billable = 1) or (@Billable = 2 and PC.Billable = 0)) 

     Union All 
     select distinct 
     Isnull(U.LastName,'') + ', ' + IsNull(U.Firstname,'') as Clinician, 
     convert(varchar(15),P.DateOfService,101) as DateOfService, 
     P.PaceID, 
     Dem.LastName + ', ' + Dem.FirstName as ClientName, 
     P.ID as ProgressNoteID, 
     PC.BillingCodeID, 
     PC.ProgressNoteType, 
     BC.Code, 
     PC.POS, 
     BC.MOD1, 
     BC.MOD2, 
     Isnull(BC.Code,'') + ' ' + ISnull(PC.POS,'') + ' ' + ISNULL(BC.MOD1,'') + ' ' + ISNULL(BC.MOD2,'') as FullHCPC, 
     PC.Units, 
     PC.TimeIn, 
     PC.TimeOut, 
     DateDiff(mi,pc.TimeIn,pc.TimeOut) as Minutes, 
     Case when Datediff(mi,PC.TimeIn,PC.TimeOut)/60 > 0 
     then Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut)/60) + 'h ' + Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut) % 60) + 'm' else Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut) % 60) + 'm' end as TimeDesc, 
     I.BehavioralHealthCategory, 
     L3.Description as Program, 
     case when p.DateOfService > '8/1/13' and PC.BillingCodeID in (3,4) and PC.DOCID is null then 'Log Missing' else convert(varchar(20),PC.DocID) end as TransportationLog, 
     P.LateEntry, 
     a.currentlocation as Status 
     from tblCrisisProgressNotes P 
     left join tblProgressNoteCodes PC on PC.ProgressNoteID = P.ID and PC.ProgressNoteType = 2 
     left join tblLicensure L on L.ProviderID = P.ClinicianID and L.[Primary] = 1 and P.DateOfService >= L.StartDate and (L.EndDate is null or L.EndDate >= P.DateOfService) 
     left join tblLookups L2 on L2.Code = L.LicenseTypeID and L2.CategoryID = 48 
     left join tblLookups L3 on L3.Code = P.Program and L3.CategoryID = 104 
     left join #tmpRates R on R.BillingCodeID = PC.BillingCodeID and R.POS = PC.POS and R.LicenseGroupID = L2.Type and R.Billable = PC.Billable and R.ProviderID = P.Site 
      and R.StartDate <= p.DateOfService and R.EndDate >= p.DateOfService 
     left join tblBillingCodes BC on BC.ID = PC.BillingCodeID 
     left join tblDemographics Dem on Dem.PaceID = P.PaceID 
     left join tblIntakes I on I.ID = P.IntakeID 
     left join tblReferrals CR on CR.ID = I.ReferralID 
     left join tblProviders PP on PP.ID = P.ClinicianID 
     left join vwUsers U on U.ID = PP.UserID 
     left join tblactivities A on A.extid1 = P.paceid and A.extid2 = P.ID and A.completedDate is null and A.currentlocationid in (select locationid from tbllocations where workflowid = 4) and A.visible = 1 and A.extid4 = 2 
     where P.DateOfService >= @StartDate and P.DateOfService <= @EndDate 
     and P.Deleted = 0 
     and PC.Void = 0 
     and (@Status is null or (a.currentlocationID = @Status)) 
     and (@Program is null or (P.Program in (select program from #T1))) 
     and (@Clinician is null or (P.ClinicianUserID = @Clinician)) 
     and (@LateEntryOnly = 0 or (P.LateEntry = @LateEntryOnly)) 
     and ((@Billable = 0) or (@Billable = 1 and PC.Billable = 1) or (@Billable = 2 and PC.Billable = 0)) 

     Union All 
     select distinct 
     Isnull(U.LastName,'') + ', ' + IsNull(U.Firstname,'') as Clinician, 
     convert(varchar(15),p.DateOfService,101) as DateOfService, 
     P.PaceID, 
     Dem.LastName + ', ' + Dem.FirstName as ClientName, 
     P.ID as ProgressNoteID, 
     PC.BillingCodeID, 
     PC.ProgressNoteType, 
     BC.Code, 
     PC.POS, 
     BC.MOD1, 
     BC.MOD2, 
     Isnull(BC.Code,'') + ' ' + ISnull(PC.POS,'') + ' ' + ISNULL(BC.MOD1,'') + ' ' + ISNULL(BC.MOD2,'') as FullHCPC, 
     PC.Units, 
     PC.TimeIn, 
     PC.TimeOut, 
     DateDiff(mi,pc.TimeIn,pc.TimeOut) as Minutes, 
     Case when Datediff(mi,PC.TimeIn,PC.TimeOut)/60 > 0 
     then Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut)/60) + 'h ' + Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut) % 60) + 'm' else Convert(varchar(2),Datediff(mi,PC.TimeIn,PC.TimeOut) % 60) + 'm' end as TimeDesc, 
     I.BehavioralHealthCategory, 
     case when p.DateOfService > '8/1/13' and PC.BillingCodeID in (3,4) and PC.DOCID is null then 'Log Missing' else convert(varchar(20),PC.DocID) end as TransportationLog, 
     L3.Description as Program, 
     P.LateEntry, 
     a.currentlocation as Status 
     from tblPersonalProgressNotes P 
     left join tblProgressNoteCodes PC on PC.ProgressNoteID = P.ID and PC.ProgressNoteType = 3 
     left join tblLicensure L on L.ProviderID = P.ClinicianID and L.[Primary] = 1 and P.DateOfService >= L.StartDate and (L.EndDate is null or L.EndDate >= P.DateOfService) 
     left join tblLookups L2 on L2.Code = L.LicenseTypeID and L2.CategoryID = 48 
     left join tblLookups L3 on L3.Code = P.Program and L3.CategoryID = 104 
     left join #tmpRates R on R.BillingCodeID = PC.BillingCodeID and R.POS = PC.POS and R.LicenseGroupID = L2.Type and R.Billable = PC.Billable and R.ProviderID = P.Site 
      and R.StartDate <= p.DateOfService and R.EndDate >= p.DateOfService 
     left join tblBillingCodes BC on BC.ID = PC.BillingCodeID 
     left join tblDemographics Dem on Dem.PaceID = P.PaceID 
     left join tblIntakes I on I.ID = P.IntakeID 
     left join tblReferrals CR on CR.ID = I.ReferralID 
     left join tblProviders PP on PP.ID = P.ClinicianID 
     left join vwUsers U on U.ID = PP.UserID 
     left join tblactivities A on A.extid1 = P.paceid and A.extid2 = P.ID and A.completedDate is null and A.currentlocationid in (select locationid from tbllocations where workflowid = 4) and A.visible = 1 and A.extid4 = 3 
     where P.DateOfService >= @StartDate and P.DateOfService <= @EndDate 
     and P.Deleted = 0 
     and PC.Void = 0 
     and (@Status is null or (a.currentlocationID = @Status)) 
     and (@Program is null or (P.Program in (select program from #T1))) 
     and (@Clinician is null or (P.ClinicianUserID = @Clinician)) 
     and (@LateEntryOnly = 0 or (P.LateEntry = @LateEntryOnly)) 
     and ((@Billable = 0) or (@Billable = 1 and PC.Billable = 1) or (@Billable = 2 and PC.Billable = 0)) 
     order by Clinician, DateOfService,Code, POS, MOD1, MOD2 ,ClientName, TimeIn 
     END 

     drop table #tmpRates 
     drop table #T1 
+0

替換'和'='in'再檢查。 – Utsav

回答

0

下面替換查詢:

set @SQLQuery = ' select distinct program from tblProgNotes where Program in (' + @Program + ')' 

https://msdn.microsoft.com/en-us/library/ms177682.aspx

+0

現在,此錯誤正在導致運行:System.Data.SqlClient.SqlException:')'附近的語法不正確。 –

+0

請提供您正在傳遞的輸入(@program) –

+0

set @SQLQuery ='從Rms.Devices中選擇不同的DeviceIntID,其中DeviceIntID在('+ CAST(@Program AS VARCHAR(10))+')' –