为什么不能在 CONTAINS 语句中调用 ISNULL? [英] Why can't ISNULL be called inside a CONTAINS statement?

查看:24
本文介绍了为什么不能在 CONTAINS 语句中调用 ISNULL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这个 SQL 查询:

Let's say I have this SQL query:

declare @input varchar(20)
select *
from myTable
where CONTAINS (myColumn, ISNULL(@input, 'replacement text'))

如果我尝试执行此操作,则会收到一条错误消息,指出'ISNULL' 附近的语法不正确."我知道这是 ISNULL 的正确语法.有什么原因不能在 CONTAINS 语句中调用 ISNULL?

If I try to execute this, I get an error that says "Incorrect syntax near 'ISNULL'." I know that this is the correct syntax for ISNULL. Is there a reason why the ISNULL cannot be called inside of the CONTAINS statement?

推荐答案

试试这个:

declare @input varchar(20)
SET @input=ISNULL(@input, 'replacement text')
select *
from myTable
where CONTAINS (myColumn, @input)

当您尝试将表达式放入存储过程调用时也是同样的问题:

it is the same problem when you try to put an expression into a stored procedure call:

EXEC YourProcedure ISNULL(@input, 'replacement text') --will fail too

CONTAIN 需要字符串文字,请参阅 CONTAINS (Transact-SQL)

CONTAIN expects a string literal, see CONTAINS (Transact-SQL)

这篇关于为什么不能在 CONTAINS 语句中调用 ISNULL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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