2015-05-14 62 views
1

我對supplier_search查詢是存儲過程的搜索..與空值

CREATE DEFINER=`root`@`localhost` PROCEDURE `supplier_Search`(in strLedgerName varchar(255),in strAddress varchar(255), 
     in inPhoneNo int(45), in inMobNo int(45), in strPriceLevel varchar(255),in strCountry varchar(255),in strState varchar(255)) 
BEGIN 
    if inPhoneNo = '' then SET inPhoneNo =Null ;end if; 
    if inMobNo = '' then SET inMobNo =Null ;end if; 
    if strLedgerName ='' then SET strLedgerName = Null; end if;  
    if strAddress ='' then set strAddress = null; end if;  
    if strPriceLevel = '' then set strPriceLevel = null; end if; 
    if strCountry = '' then set strCountry = null; end if; 
    if strState = '' then set strState = null; end if; 
    select ledgerName,address, phoneNo , mobNo ,priceLevel,stateName, CountryName from 
    (
     select joined_ab.ledgerName,joined_ab.address ,joined_ab.phoneNo, joined_ab.mobNo ,joined_ab.priceLevel,c.countryName,joined_ab.stateId 
     from (select a.ledgerName, a.address , a.phoneNo , a.mobNo ,b.priceLevel, 
     a.countryId,a.stateId from tbl_ledger as a inner join tbl_price_level as b on a.pricingLevelId =b.priceLevelId) 
     as joined_ab inner join tbl_country as c on joined_ab.countryId = c.countryId 
    ) as joined_abc inner join tbl_state 
    as d on joined_abc.stateId = d.stateId 
    where((strLedgerName is null or joined_abc.ledgerName LIKE concat(strLedgerName,"%")) 
    and(strAddress is null or address LIKE concat(strAddress ,"%")) 
    and(inPhoneNo is Null or phoneNo lIke concat(inPhoneNo , "%")) 
    and (strPriceLevel is null or priceLevel Like concat(strPriceLevel,"%"))  
    and(inMobNo is Null or mobNo Like concat(inMobNo , "%")) 
    and(strCountry is null or CountryName LikE concat(strCountry,"%")) 
    and(strState is null or StateName LikE concat(strState,"%"))); 
END 

我想,當一個或一個以上的值傳遞給獲取輸出。 但問題是,當我不mobileNo或PHONENO傳遞價值和執行錯誤是

call db_account.supplier_Search('1', '', '', '', '', '', '')  
Error Code: 1366. Incorrect integer value: '' for column 'inPhoneNo' at row 1 0.000 sec 
+0

是否有可能使用'null'值調用thw過程,如'調用db_account.supplier_Search('1','null,null,null,null,null,null)' – sevenforce

+0

yes是可以的。你不是嗎? –

回答

1

的問題是由於你傳遞一個整數值作爲「」。

SQL不知道哪種類型的整數是;嘗試設置0或NULL。

環境提示您問題是:您使用''作爲整數值,SQL不知道哪種類型的整數;嘗試設置0或NULL。如果問題不在調用操作中,則必須更改在過程正文中比較數據的方式:

if inPhoneNo =''then SET inPhoneNo = Null; end if;

+0

嘗試設置0 r null。但仍然不起作用 –

+0

結果是一樣的嗎? – Simone

+0

不好意思,我注意到現在你說的是mysql ...我是通過sql-server過濾的......在任何情況下,我都會嘗試去第1行並更改爲不同的值:如果它不是在調用者中,它必須位於sp體中,您將一個整數與一個空字符串進行比較('') – Simone