Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Select Problem

Status
Not open for further replies.

choudhmh

Programmer
Aug 9, 2004
34
GB
Hi Guys
I have two table tblTelephoneCallPlans which has fileds TelephoneCallPlansID, TelephoneSuppliersID and TelephoneCallPlanName.
tblTelephoneSuppliers has fields tblTelephoneSuppliersID and TelephoneSupplierName.

I'm trying to us the select procedure to select the the TelephoneCallPlanName according to TelephoneSuppliersID with parameter @TelephoneSuppliersID.

I tried doing it like this:

Select Distinct
TelephoneCallPlanName
From tblTelephoneCallPlans, tblTelephoneSuppliers
Where
Enabled <> 0
AND
TelephoneSupplierID = @TelephoneSupplierID


But keep on getting errors.
Does anyone knows what i needs to amend
Thanks,
Mac
 
What errors are you getting?

Did you define the @TelephoneSupplierID with a Declare statement?
 
yes
in the store procedure

CREATE Procedure sp_getTelephoneCallPlans
@TelephoneSupplierID int
AS

Depening on the TelephoneSupplierID call plan name should be shown
 
Sorry for the hassel guys but found the answere after test and trials:

CREATE Procedure sp_getTelephoneCallPlans
@TelephoneSupplierID int
AS
Select Distinct
TelephoneCallPlanName
From tblTelephoneCallPlans TS
Where
Enabled <> 0
AND
TS.TelephoneSupplierID = @TelephoneSupplierID

GO

GRANT EXEC ON sp_getTelephoneCallPlans TO PUBLIC

GO

It return the CallPlanName according to the parameter.
Maca
 
You need to join the 2 tables together somehow.

Ex:

Code:
Select Distinct 
TelephoneCallPlanName
From tblTelephoneCallPlans  tcp
JOIN tblTelephoneSuppliers  ts
ON   tcp.telephoneSupplierId = ts.telephoneSupplierId 
Where
Enabled <> 0
AND
tcp.TelephoneSupplierID = @TelephoneSupplierID

What table is Enabled in, and have you verified that this is not equal to 0?
 
sorry youre procedure does not function. theres no need to do any joins, tblTelephoneSuppliers is not needed.
Thanks for all your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top