有没有办法创建这样的用户定义函数

时间:2021-12-23 16:33:02

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

我是TSQL的新手,我正在尝试创建一个计算经度并给出半径的函数。我知道如何在C#中实现它,但现在很难将其转换为T-SQL,这是多部分功能

   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

所有这一切的答案都是第3步,我想把它放在这里

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 个解决方案

#1


1  

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

是的,您可以在T-SQL中完成它,但与C#,C ++和大多数编程语言相比,它的性能会很差:

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.

我只是用你自己的计算方法。

#1


1  

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

是的,您可以在T-SQL中完成它,但与C#,C ++和大多数编程语言相比,它的性能会很差:

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.

我只是用你自己的计算方法。