I have this SP:
CREATE PROCEDURE GetFarmDetails
(@.FarmID varchar(200))
AS
SELECT Name, Address1,Address2, County,Postcode,TelNo,FaxNo,MobileNo,Contact,CustNo,StatusID,RepID FROM Customers
WHERE CustomerID = @.CustomerID
RETURN
GO
But I want the SQL to find the StatusName and RepName from the Status and Rep table according to the StatusID and RepID returned above. Could this be added to the above SQL and I get the StatusName and RepName from the one SP?
Thanks for any help.
Simon
yes do you have any PK-FK relation with the other two tables youmentioned? you need to provide us the data structure too for someone tohelp you out..|||
Yes there are Pk-FK relationships between Rep and Status tables and Customers.
Thanks
Simon
|||Sorry, the SP should read:CREATE PROCEDURE GetFarmDetails
(@.CustomerIDvarchar(200))
AS
SELECT Name, Address1,Address2, County,Postcode,TelNo,FaxNo,MobileNo,Contact,CustNo,StatusID,RepID FROM Customers
WHERE CustomerID = @.CustomerID
RETURN
GO
Simon
|||
Hello,
Here is the Solution.
SELECT Status.StatusName , Rep.RepName FROM
Customer C
LEFT OUTER JOIN Status
ON StatusID = C.StatusID
LEFT OUTER JOIN Rep
ON RepID = C.RepID
WHERE
CustomerID = @.CustomerID
Here you go little one,
Hope it will work out well
Regards
KeanXSoul
|||Just the job, will post the final SP later for others.Simon
No comments:
Post a Comment