本文介绍了我的查询有什么问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
declare @vc_supplier_name varchar(200) =''
declare @in_supplier_type_id int =2
declare @bt_active bit =1
SELECT a.in_supplier_id, dbo.format_fnc_bit(1, a.bt_active) AS vc_active, b.vc_supplier_type_name, a.in_supplier_type_id, a.vc_supplier_name,
dbo.admin_user_fnc_get_name(1, a.in_updatedby_user_id) AS vc_updated_by, a.dt_updated
FROM dbo.supplier a
INNER JOIN dbo.common_data_vw_supplier_type b ON a.in_supplier_type_id = b.in_supplier_type_id
WHERE a.in_supplier_type_id = @in_supplier_type_id AND a.vc_supplier_name LIKE '%' + @vc_supplier_name + '%'
AND a.bt_active = case @in_supplier_type_id when 2 THEN @bt_active
ORDER BY a.vc_supplier_name
出现错误:关键字''ORDER''附近的语法不正确。
这里我想使用bt_active只有@in_supplier_type_id = 2
Error comes :Incorrect syntax near the keyword ''ORDER''.
here i want to use bt_active only if @in_supplier_type_id=2
推荐答案
引用:
案例@in_supplier_type_id当2那么@bt_active
case @in_supplier_type_id when 2 THEN @bt_active
你在这里错过了结尾 END
(:-))。
AND a.bt_active = case @in_supplier_type_id when 2 THEN @bt_active
应该是这样的:
should be this:
AND a.bt_active = case @in_supplier_type_id when 2 THEN @bt_active End
如果需要,你也可以使用Else。
You can also use an Else if need be.
这篇关于我的查询有什么问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!