hey guys im creating a stored procedure for search form in the asp.net im getting error, code is given below
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
im getting this error
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'
can any help me please
In general, you’ll get an “ambiguous column name” error when you’re performing a select that joins multiple tables together that have at least one column with the same name, and then you reference that column without prefixing it with the table.
So I your case I would assume that the
customervendornamecolumn appears in more than one table (perhapsCustomerVendorDetailsandCustomerVendorAddressDetails?) so when you use it in the where clause you’ll need to prefix it with the table name. I see in fact that you’ve already done this in the list of columns to be selected; you just need to do the same throughout the statement.Thus
needs to become
and possibly similar changes for the other constraints.