2010-11-13 81 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在哪里条件将工作。