简体   繁体   English

在存储过程中获取exec sql语句的值

[英]getting value of exec sql statement within stored procedure

I am running several select statements and need to check the values of each select statement, and in some cases compare them to values of other select statements all from within the same stored procedure and then return a value back to my program. 我正在运行几个select语句,需要检查每个select语句的值,在某些情况下,它们都与同一存储过程中所有其他select语句的值进行比较,然后将值返回给我的程序。 Here is some of my code: 这是我的一些代码:

DECLARE @statement AS VARCHAR(MAX)
Declare @result as integer

set @statement = 'SELECT Count (*) FROM tooling.dbo.PTA00015 Where PTA00015.TD0001 = ''' +   @ToolCode + '''' 
Exec (@statement)

I need the value from this to know if the return value is 0 or not. 我需要从中得知返回值是否为0的值。 IF <> 0 I have another select statement that when it returns a value I need to compare that to this original select statement. IF <> 0我有另一个选择语句,当它返回一个值时,我需要将其与原始选择语句进行比较。 Depending on if they match I need to return a value back to my program basically MATCH or NOT MATCH. 根据它们是否匹配,我基本上需要将值返回到我的程序MATCH或NOT MATCH。

How do I get the value from the EXEC and use that for comparison? 我如何从EXEC获得价值并将其用于比较?

Why dont you simply use 你为什么不简单地使用

set @count = SELECT Count (*) FROM tooling.dbo.PTA00015 Where PTA00015.TD0001 =  @ToolCode 

And use @count directly to compare with the other value? 并直接使用@count与其他值进行比较?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM