2010-11-13 70 views
2

嘿傢伙即時通訊建立在asp.net即時搜索表單得到錯誤的存儲過程,代碼如下存儲過程的錯誤「曖昧列」

set ANSI_NULLS ON 
set QUOTED_IDENTIFIER ON 
go 

ALTER PROCEDURE [dbo].[sp_searchcustomervendordetails] 
@customervendortype varchar(30)=Null, 
    @customervendorid varchar(30)=Null, 
    @customervendorname varchar(30)=Null, 
    @state    varchar(30)=Null, 
    @city    varchar(30)=Null 
AS 
BEGIN 
SET NOCOUNT ON; 
--if @customervendortype is not null and len(@customervendortype)=0 set @customervendortype = null 
--if @customervendorid is not null and len(@cuatomervendorid)=0 set @customervendorid = null 
--if @customervendorname is not null and len(@customervendorname)=0 set @customervendorname = null 
--if @city is not null and len(@city)=0 set @city = null 
--if @state is not null and len(@state)=0 set @state = null 

    -- Insert statements for procedure here 
SELECT  CustomerVendorDetails.customervendorid AS CustomerVendorID,CustomerVendorAddressDetails.customervendorname, CustomerVendorAddressDetails.doorno, CustomerVendorAddressDetails.street, 
      CustomerVendorAddressDetails.city, CustomerVendorAddressDetails.state, CustomerVendorAddressDetails.country, 
      CustomerVendorAddressDetails.pincode, CustomerVendorDetails.decidingauthority, 
      CustomerVendorDetails.landlineno1, CustomerVendorDetails.landlineno2, CustomerVendorDetails.faxno, ContactPersonDetails.contactno, 
      ContactPersonDetails.designation 
FROM  CustomerVendorDetails INNER JOIN 
      CustomerVendorAddressDetails ON CustomerVendorDetails.customervendorid = CustomerVendorAddressDetails.customervendorid INNER JOIN 
      ContactPersonDetails ON CustomerVendorAddressDetails.customervendorid = ContactPersonDetails.customervendorid 
WHERE  (@customervendortype is null or customervendortype like @customervendortype) 
     or (@customervendorid is null or customervendorid like @customervendorid) 
     or (@customervendorname is null or customervendorname like @customervendorname) 
     or (city is null or city like @city) 
     or (state is null or state like @city) 
END 

即時得到這個錯誤

Msg 209, Level 16, State 1, Procedure sp_searchcustomervendordetails, Line 34 
Ambiguous column name 'customervendorid'. 
Msg 209, Level 16, State 1, Procedure sp_searchcustomervendordetails, Line 35 
Ambiguous column name 'customervendorname' 
給出

任何幫助我請

回答

1

一般來說,當您執行一個選擇,將多個表連接在一起,並至少有一列具有相同的納姆,你會得到一個「模棱兩可的列名」錯誤e,然後您引用該列而不用在表中添加前綴。

所以我你的情況我會假設customervendorname柱出現在多個表(也許CustomerVendorDetailsCustomerVendorAddressDetails?),所以當你在WHERE子句中使用它,你將需要使用表名前綴它。事實上,我已經看到你已經在要選擇的列的列表中做了這個;你只需要在整個陳述中做同樣的事情。

因此

WHERE (@customervendortype is null or 
     customervendortype like @customervendortype) 

需要變得

WHERE (@customervendortype is null or 
     CustomerVendorAddressDetails.customervendortype like @customervendortype) 

和可能的其他約束類似的變化。

+0

感謝朋友的工作 – Raj 2010-11-13 14:10:20

0

的問題必須在這一部分:

or (@customervendorid is null or customervendorid like @customervendorid) 
     or (@customervendorname is null or customervendorname like @customervendorname) 

你應該檢查,如果你在你的CustomerVendorAddressDetails和ContactPersonDetails表customervendorid和customervendorname列

0

(@customervendorid爲空或customervendorid像@customervendorid)或(@customervendorname爲空或客戶名稱爲@customervendorname)

檢查這兩條線..

請發佈您的客戶和您正在使用的其他表的結構。這將很容易猜到錯誤

0

CustomerVendorDetails.customervendorid和customerVendorname替換customervendorid由CustomerVendorAddressDetails.customervendname在哪裏條件將工作。