SQL Server:将布尔值转换为整数 [英] SQL Server: Cast bool as integer

查看:592
本文介绍了SQL Server:将布尔值转换为整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么查询:

SELECT CAST((column LIKE '%string%') AS INT)+100

返回

关键字"AS"附近的语法不正确

推荐答案

因为bool不是T-SQL中的类型.它不存在.布尔表达式不是bit类型的.它们没有具有类型-仅在特殊地方语法允许的情况下才允许使用.是的,这太糟糕了.

Because bool is not a type in T-SQL. It does not exist. Boolean expressions are not of type bit. They don't have a type - they are only allowed if allowed by the grammar in special places. And yes, this is awful.

SELECT (case when (column LIKE '%string%') then 1 else 0 end)+100

这篇关于SQL Server:将布尔值转换为整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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