条件不起作用的存储过程

时间:2021-12-09 16:38:06

This is my stored procedure to select data from a table. but if I put where condition in it. Then it is throwing an error

这是我从表中选择数据的存储过程。但如果我把条件放在其中。然后它抛出一个错误

"Incorrect syntax near '='."

“'='附近的语法不正确。”

But if i remove where condition then this query will work fine. can anyone please tell me what i am doing wrong in where condition.

但是,如果我删除where条件,那么这个查询将正常工作。任何人都可以告诉我,我在哪里做错了什么。

alter procedure [dbo].[GetCompleteCPTDetails]
    @Practice_Short_Name varchar(50) = null,
    @Uploaded_Date varchar(max) = null
as
begin
DECLARE @CPTtablename varchar(100)
DECLARE @vQuery NVARCHAR(max)
set @CPTtablename = 'ACER_CLAIMS_MASTER_DETAIL_Hist_'+@Practice_Short_Name+''
SET @vQuery = 'select Practice_Short_Name,Service_Date_From,Carrier_Name,
   Location_Description,Patient_Number,Patient_First_Name,
   Patient_Last_Name,Voucher_Number,Procedure_Code,Service_Fees,
   Service_Payments,Service_Adjustments,Acer_Status,Acer_Allowed_Amount    
from ' + @CPTtablename + 'where Uploaded_Date ='+ @Uploaded_Date +'
order by acer_status asc, Service_Date_From desc, Patient_First_Name asc'

EXEC (@vQuery)

end
GO

1 个解决方案

#1


For date @Uploaded_Date you need quotas as below

对于约会@Uploaded_Date,您需要如下配额

alter procedure [dbo].[GetCompleteCPTDetails]
    @Practice_Short_Name varchar(50) = null,
    @Uploaded_Date varchar(max) = null
as
begin
DECLARE @CPTtablename varchar(100)
DECLARE @vQuery NVARCHAR(max)
set @CPTtablename = 'ACER_CLAIMS_MASTER_DETAIL_Hist_'+@Practice_Short_Name+''
SET @vQuery = 'select Practice_Short_Name,Service_Date_From,Carrier_Name,
   Location_Description,Patient_Number,Patient_First_Name,
   Patient_Last_Name,Voucher_Number,Procedure_Code,Service_Fees,
   Service_Payments,Service_Adjustments,Acer_Status,Acer_Allowed_Amount    
from ' + @CPTtablename + ' where Uploaded_Date ='''+ @Uploaded_Date +'''
order by acer_status asc, Service_Date_From desc, Patient_First_Name asc'

EXEC (@vQuery)

end
GO

#1


For date @Uploaded_Date you need quotas as below

对于约会@Uploaded_Date,您需要如下配额

alter procedure [dbo].[GetCompleteCPTDetails]
    @Practice_Short_Name varchar(50) = null,
    @Uploaded_Date varchar(max) = null
as
begin
DECLARE @CPTtablename varchar(100)
DECLARE @vQuery NVARCHAR(max)
set @CPTtablename = 'ACER_CLAIMS_MASTER_DETAIL_Hist_'+@Practice_Short_Name+''
SET @vQuery = 'select Practice_Short_Name,Service_Date_From,Carrier_Name,
   Location_Description,Patient_Number,Patient_First_Name,
   Patient_Last_Name,Voucher_Number,Procedure_Code,Service_Fees,
   Service_Payments,Service_Adjustments,Acer_Status,Acer_Allowed_Amount    
from ' + @CPTtablename + ' where Uploaded_Date ='''+ @Uploaded_Date +'''
order by acer_status asc, Service_Date_From desc, Patient_First_Name asc'

EXEC (@vQuery)

end
GO