2017-01-10 129 views
0
BEGIN 
DECLARE cnt1 int(11); 
DECLARE cnt2 int(11); 
DECLARE demandid varchar(255); 
set demandid = replace(pintypeid,';',','); 

SELECT 
    COUNT(*) into cnt1 
FROM 
    UK_Generic_Demand_Details 
where status =300 and 
policyNumber =pinpno and 
demandTypeId in(Select @demandid) ; 

    SELECT 
    COUNT(*) into cnt2 
FROM 
    UK_Generic_Completed_Demand_Details 
    where 
     status =300 and 
policyNo =pinpno and 
demandTypeId in(select @demandid); 
     select cnt1+cnt2 into poutcount; 

END 

可以請一些建議我解決這個問題。 存儲過程將從應用程序調用pintypeid和policynumber作爲輸入。 policynumber將單個,但pintypeid將像一個字符串。mysql select不工作IN IN

回答

1

您可能正在尋找find_in_set

BEGIN 
DECLARE cnt1 int(11); 
DECLARE cnt2 int(11); 
DECLARE demandid varchar(255); 
set demandid = replace(pintypeid,';',','); 

SELECT 
    COUNT(*) into cnt1 
FROM 
    UK_Generic_Demand_Details 
where status =300 and 
policyNumber =pinpno and 
find_in_set(demandTypeId, @demandid) > 0; 

    SELECT 
    COUNT(*) into cnt2 
FROM 
    UK_Generic_Completed_Demand_Details 
    where 
     status =300 and 
policyNo =pinpno and 
find_in_set(demandTypeId, @demandid) > 0; 
     select cnt1+cnt2 into poutcount; 

END 
+0

我已經試過了太.. – Chowdary

+0

@sravan話,請添加更多詳細的問題 - 像什麼都會變有它。該專欄有什麼。 – GurV