在SQL Server函数中使用序列 [英] Use a Sequence in a function SQL Server

查看:74
本文介绍了在SQL Server函数中使用序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在T-SQL函数中使用序列,但是T-SQL不允许使用 Next Value for ,而 OPENROWSET 不允许使用'由于数据库的安全性,不允许我进行查询.

I'm trying to use a sequence inside a T-SQL function but T-SQL doesn't allow the use of Next Value for, and OPENROWSET doesn't allow me to do queries because of the security of the database.

CREATE FUNCTION dbo.newInvoice()
RETURNS varchar
AS
BEGIN
    DECLARE @NumberHold AS bigint

    SELECT 
        @NumberHold = NEXT VALUE FOR dbo.Ten_Seq

    RETURN 
        dbo.sfnSprintf('MyOmnyInvoice[%s]', CAST(@NumberHold as varchar), default);
END

推荐答案

您不能在内置函数中使用 NEXT VALUE FOR 函数

You cannot use NEXT VALUE FOR function in built-in functions

根据 MSDN

限制和限制

在视图,用户定义函数或计算列中.

In views, in user-defined functions, or in computed columns.

这篇关于在SQL Server函数中使用序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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