Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Procedure with Joins

Author  Topic 

mellamokb
Starting Member

39 Posts

Posted - 2005-12-30 : 10:41:59
Hi,

I need to write a procedure that retrieves a list of contacts from a contact table, in which the contact types are stored by id; I only want the contacts that are a certain contact type [prospector], but I want to use the contact type name, not ID to compare because that should never change, while the ID could change. Another table contains the contact types with ID's to link them to the contact table. Here is the code I use, but when I retrieve the information from the procedure using a page online, the page stops loading after the procedure is executed:

--------------------- CODE -------------------
CREATE Procedure getProspectors

AS

SELECT
[contact table].ID,
[contact table].contact

FROM [contact table]

INNER JOIN [contact types table] ON
[contact table].contactType = [contact types table].ID

WHERE [contact types table].contactType = 'prospector'

ORDER BY contact ASC


RETURN
GO
---------------------- END CODE ----------------

I don't really know that much about SQL - I copied the idea from some other procedures. Is there a reason why this wouldn't work?

thanks,
melloamokb

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2005-12-30 : 12:35:33
Try the following :
1. Run the SQL Query alone, in Query Analyzer and c whether it gives any result
2. Run the stored procedure in Query Analyzer and c whether it gives any result
3. Remove the Return & check the result
4. Write a simple Query (Select * from contacts) & check the result
5. Put Begin & End in the begining & in the end respectively, in the Procedure.
Another idea : U can have this query written in a View & get the desired result.
Go to Top of Page
   

- Advertisement -