gpt4 book ai didi

sql - 在预期条件的上下文中指定的非 bool 类型的表达式,接近 '@orderwhere'

转载 作者:行者123 更新时间:2023-12-04 02:50:52 24 4
gpt4 key购买 nike

为什么以下语法会产生错误“An expression of non-boolean type specified in a context where a condition is expected, near '@orderwhere'”

use orders
declare @orderwhere varchar(5000)
set @orderwhere = 'order_status.step = 1'
select order_status.order_id
from order_status
where @orderwhere

最佳答案

您的查询部分不能是动态的。它必须是全有或全无。然后使用 EXEC()运行您的动态查询

exec('select order_status.order_id
from order_status
where ' + @orderwhere)

关于sql - 在预期条件的上下文中指定的非 bool 类型的表达式,接近 '@orderwhere',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17786677/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com