从SQL存储过程返回BIT常量 [英] Return BIT constant from SQL Stored Procedure

查看:246
本文介绍了从SQL存储过程返回BIT常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定,我要从存储过程返回BIT常量。



我设法得到这个编译的唯一方法是使用转换:



CAST(0 AS BIT)AS MyBool



有没有更高效的方式来写这个没有转换?

解决方案

有些人喜欢做以下事情:

  declare @True bit,@ False bit 
set @True = 1
set @False = 0

然后在查询的剩余部分使用 @True @False p>

我想象,后编译两种方法之间的效率差异是如此微小,你可以安全地写在任何你喜欢的风格。


OK, I'm trying to return a BIT constant from a Stored Procedure.

The only way I've managed to get this to compile is using a cast:

CAST(0 AS BIT) AS MyBool

Is there a more efficient way to write this without a cast?

解决方案

Some people prefer to do the following

declare @True bit,@False bit
set @True = 1
set @False = 0

And then use @True or @False for the remainder of their query.

I would imagine that post compilation the difference in efficiency between the two methods is so vanishingly small you can safely write it in whatever style you prefer.

这篇关于从SQL存储过程返回BIT常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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