newid() inside sql server function(sql server 函数中的 newid())
问题描述
我必须在查询结果中插入一个假列,它是表值函数的返回值.此列数据类型必须是唯一标识符.最好的方法(我认为...)是使用 newid()
函数.问题是,我不能在这种类型的函数中使用 newid()
:
I have to insert a fake column at the result of a query, which is the return value of a table-value function. This column data type must be unique-identifier. The best way (I think...) is to use newid()
function. The problem is, I can't use newid()
inside this type of function:
Invalid use of side-effecting or time-dependent operator in 'newid()' within a function.
推荐答案
这里有一个聪明的解决方案:
here's a clever solution:
create view getNewID as select newid() as new_id
create function myfunction ()
returns uniqueidentifier
as begin
return (select new_id from getNewID)
end
我无法相信这一点.我在这里找到了:http://omnibuzz-sql.blogspot.com/2006/07/accessing-non-deterministic-functions.html
that i can't take credit for. i found it here: http://omnibuzz-sql.blogspot.com/2006/07/accessing-non-deterministic-functions.html
-唐
这篇关于sql server 函数中的 newid()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:sql server 函数中的 newid()


基础教程推荐
- 在多列上分布任意行 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01