newid()里面的sql server功能 [英] newid() inside sql server function

查看:102
本文介绍了newid()里面的sql server功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在查询结果中插入一个伪列,这是表值函数的返回值。此列数据类型必须是唯一标识符。最好的方法(我认为...)是使用 newid()函数。问题是,我不能在这种类型的函数中使用 newid()

 函数中'newid()'中副作用或时间依赖运算符的使用无效。 


解决方案

这是一个巧妙的解决方案:
$ b $ p $ create view getNewID as newid()as new_id

create function myfunction()
return uniqueidentifier
开始
返回(从getNewID中选择new_id)
结束

不能信任。我在这里找到了:
http:// omn​​ibuzz-sql.blogspot.com/2006/07/accessing-non-deterministic-functions.html



-don


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

that i can't take credit for. i found it here: http://omnibuzz-sql.blogspot.com/2006/07/accessing-non-deterministic-functions.html

-don

这篇关于newid()里面的sql server功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆