使用 FUNCTION 的 sql select 语句,无需访问 .Net 中的 SQL DB
我有一个只有读者权限的 SQL 数据库,因此我无法添加我唯一的存储过程或函数,并且我正在寻找一种方法来完成我的任务而无需获得管理员权限(该软件仅具有开发人员的读者权限,并且没有允许完全访问,这就是为什么我正在寻找另一种方法)
我拥有的是一个我想从中提取记录的表,但要做到这一点,需要对字段进行一些计算以计算出长度。
有没有一种方法可以在.Net 中或使用我可以运行的 SQL 脚本文件来完成此任务? 不确定我是否需要尽一切努力才能获得所需的结果 - 创建临时表 -插入表中的临时表字段和计算值 -WHERE 计算值小于 100
(现在我可以使用 CREATE 语句来做到这一点,但这不好,如上所述,没有数据库访问权限来创建任何东西..所以它需要是某种类型的动态代码,不能同时执行这两种操作select 和函数合二为一)
这是我在 .Net 代码中输入的 SQL 代码示例
BEGIN
CREATE TABLE #Listings
(
AddressID varchar(50), Street varchar(50), City varchar(50), State varchar(50),
Zip varchar(50), ZipCalculatedValue Decimal(18,12)
)
INSERT INTO #Listings (AddressID, Street, City, State, Zip, ZipCalculatedValue)
SELECT AddressID, Street, City, State, Zip, Name, bo.CalcZip(@ZIP) AS ZipCalculatedValue
FROM tbl_Addresses
WHERE dbo.dbo.CalcZip(@ZIP) <= @maxZIP
ORDER BY Distance ASC
SELECT *
FROM #Listings
,该函数
DECLARE @ZIP FLOAT
SET @ZIPCalc = (@ZIP - 1000) --more code but removed to simplify
SET @ZIPCalc = (@ZIPCalc * 10) --result above more workings removed
RETURN @ZIPCalc
在 .Net 中看起来像这样,我可以连接到数据库并获取结果,但对如何操作有任何想法我可以使用带有 SELECT 语句的 FUNCTION 来提取结果吗?
谢谢
i have a SQL DB that only have reader permissions, as so i cant add my only stored proc or functions, and i am looking for a way to complete my mission without getting admin permission (the software only have reader permissions for developers and does not allow full access, that is why I am looking for another way)
What I have is a table that i want to pull records from, but to do this there is a need to do some calculations on the fields to work out lengths.
is there a way in .Net or using an SQL script file that i can run that will accomplish this?
Not sure if I need to do all thoughts to get the required results
-create a temp table
-insert into temp table fields from a table AND the calculated value
-WHERE calculated value is less than 100
(now i can do it using CREATE statements but this is no good, as above, there is no DB access to create anything.. so it needs to be some type of dynamic code that cant do both select and functions in one)
here is a sample of the SQL code of what I am typing to get working in .Net code
BEGIN
CREATE TABLE #Listings
(
AddressID varchar(50), Street varchar(50), City varchar(50), State varchar(50),
Zip varchar(50), ZipCalculatedValue Decimal(18,12)
)
INSERT INTO #Listings (AddressID, Street, City, State, Zip, ZipCalculatedValue)
SELECT AddressID, Street, City, State, Zip, Name, bo.CalcZip(@ZIP) AS ZipCalculatedValue
FROM tbl_Addresses
WHERE dbo.dbo.CalcZip(@ZIP) <= @maxZIP
ORDER BY Distance ASC
SELECT *
FROM #Listings
and the function looks like
DECLARE @ZIP FLOAT
SET @ZIPCalc = (@ZIP - 1000) --more code but removed to simplify
SET @ZIPCalc = (@ZIPCalc * 10) --result above more workings removed
RETURN @ZIPCalc
so in .Net i can connect to the DB and get results, but any idea on how I can use a FUNCTION with a SELECT statement to pull results?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用公用表表达式来计算该值。
Use a Common Table Expression to calculate the value.