将函数值传递给MS SQL中的存储过程 [英] Pass Function value to Stored Procedure in MS SQL

查看:130
本文介绍了将函数值传递给MS SQL中的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为dbo.GetFoo()的函数。我还有一个称为AssertEqual(需要@TargetValue sql_variant,@ExpectedValue sql_variant和@Message varchar)的单元测试存储过程。



我想调用GetFoo()和检查它是否返回正确的值'X'。我的T-SQL语句是:
$ b $ pre $ exec AssertEqual dbo.GetObjectType(),'S','Check If S'

我收到此消息:

  Msg 102,Level 15,State 1,Line 1 
'。'附近的语法错误。

它似乎令dbo窒息。部分(我可以传递它一个字符串,它工作正常)。



有没有办法解决这个问题,除了为目标值声明变量?



或者:是有更好的方法来做SQL的单元测试吗?解决方案

这是T-SQL的一个限制:它不喜欢用户已定义的函数调用作为参数传递给存储过程。你必须声明一个变量。


I have a Function called dbo.GetFoo(). I also have a unit-testing Stored Procedure called AssertEqual (which takes @TargetValue sql_variant, @ExpectedValue sql_variant, and @Message varchar)

I want to call GetFoo() and check to see if it's returning the right value 'X'. My T-SQL statement is:

exec AssertEqual dbo.GetObjectType(), 'S', 'Check If S'

I get this message:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '.'.

It appears to be choking on the "dbo." part (I can pass it a literal string and it works fine).

Is there any way around this, other than declaring a variable for the targeted value?

Alternately: is there a better way to do unit testing for SQL?

解决方案

That's a limitation of T-SQL: it doesn't like user-defined function calls passed as parameters to a stored procedure. You have to declare a variable.

这篇关于将函数值传递给MS SQL中的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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