
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
ALTER FUNCTION [dbo].[fGetGalexNearbyFrame] 
(
	@_ra float, @_dec float, @_radius float, @_zoom int
)
RETURNS 
@proxTable TABLE 
(
	-- Add the column definitions for the TABLE variable here
	fieldid	char(32) NOT NULL,
	crval1	float NOT NULL,	
	crval2	float NOT NULL,
	crpix1	float NOT NULL,
	crpix2	float NOT NULL,
	cdelt1	float NOT NULL,
	cdelt2	float NOT NULL,
	crota1	float NOT NULL,
	crota2	float NOT NULL,
	width	float NOT NULL,
	height	float NOT NULL,
	zoom	int NOT NULL,
	ra_cent	float NOT NULL,
	dec_cent float NOT NULL,
	img	char(255) NOT NULL
)
AS
BEGIN
	-- Fill the table variable with the rows for your result set
	DECLARE @distance float, @diameter float, @frameDiameter float
	SET @diameter = @_radius
	SET @frameDiameter = 0.624975192141043
	INSERT @proxTable SELECT  
	    *
	    FROM galex_jpg_test
	    WHERE zoom = @_zoom
	    AND [dbo].[fAngularDistance] (@_ra, @_dec, ra_cent, dec_cent) <= (@frameDiameter + @diameter)

	RETURN 
END
GO

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

