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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Expert SQL SP help

Status
Not open for further replies.

sqlchallenged

Programmer
Apr 4, 2005
2
US
Hi everyone.. Im a ASP programmer in need of help. I have a sql query which i can seem to input into a stored procedure.

I have two tables.... zip and dealers heres the code

SQL Server vesion - use ACOS()**
sSql = "SELECT name, phone, addr1, city, state, zip " & _
"FROM dealer " & _
"WHERE zip in ( SELECT ZIP_CODE FROM zip "& _
"WHERE @radius > 3959 * ACOS(SIN(@lat/ 57.3) * SIN(LAT/ 57.3) + " & _ "COS(@lat/ 57.3) * COS(LAT/ 57.3) * " & _ "COS((LNG/ 57.3) - (@lng/ 57.3))) ) " & _
ORDER BY name

I have the access query but cant seem to get it..

Please anyhelp will be great
 
I haven't tested anything, just had a quick look, but I don't think that you need the second WHERE.

Also there may be an ambiguous reference where you have 'zip' as field and as a table as in the first part of the WHERE clause.
 
Try this (it is syntactically valid at least):

Code:
CREATE PROC myproc
	@radius int,
	@lat decimal(10, 2),
	@lng decimal(10, 2)
AS

SELECT name, phone, addr1, city, state, zip
FROM dealer
WHERE zip IN (
		SELECT ZIP_CODE
		FROM zip
		WHERE @radius > 3959 * ACOS(SIN(@lat / 57.3) * SIN(LAT / 57.3) + COS(@lat / 57.3) * COS(LAT / 57.3) * COS((LNG / 57.3) - (@lng / 57.3)))
	)
ORDER BY name

--James
 
thanks alot for the help a little tunning on my asp code and it works great..

Thnks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top