is there a way to create a user defined function like this

87 views Asked by At

I am new to TSQL and am trying to create a function that would calculate Longitude and give a radius. I know how to do it in C# but now having difficulty translating it into T-SQL this is the multi-part function

   1. double Long = (Math.Cos((double)2.55 * (Math.PI / 180)) * 69);
   2. double milesss = 10 / Long;
   3.  item.TenLonMin = Math.Round(((double)item.longitudes - milesss), 6);

The answer to all of this is step 3 and I would like to put that inside this

UPDATE zips
SET 
 TwoLonMax= answer to step 3 here

How can I go about doing this? I have bee trying to find out how I can plug in the results of user defined functions.

1

There are 1 answers

1
Tim3880 On BEST ANSWER

Yes you can do it in T-SQL but its performance will be poor, comparing with C#, C++ and most programming languages:

CREATE FUNCTION GET_ITEM_TENLONMIN(@LONGITUDES FLOAT)
RETURNS FLOAT
AS
BEGIN
DECLARE @LONG FLOAT;
SET @LONG=COS(2.55 * (PI() / 180)) * 69;
DECLARE @MILESSS FLOAT;
SET @MILESSS = 10 / @LONG;
RETURN @LONGITUDES - @MILESSS;
END;

I just used your own calculation method.