本文介绍了如何通过两列过滤数据进行全文搜索sql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i有一个查询,它有多个搜索选项,我已经应用了这样的查询





  SELECT  *  FROM    WHERE  

(( TABLE .COLUMN1 IS NULL TABLE .COLUMN1 = 0) AND @ variable1 IS NULL OR @ variable1 = 0)
OR TABLE .COLUMN1 = CASE WHEN ((@ variable1 = 0) OR @ variable1 IS NULL ))
THEN TABLE .COLUMN1 ELSE @ variable1 END

AND

(( .COLUMN2 IS NULL OR TABLE .COLUMN2 = 0) AND @ variable2 IS NULL OR @ variable2 = 0)
OR .COLUMN2 = CASE WH EN ((@ variable2 = 0) OR @ variable2 IS NULL ))
那么 TABLE .COLUMN2 ELSE @ variable2 结束





现在我的问题是针对column2我需要检查两个不同列的相同内容。 COLUMN2和COLUMN3。如果COLUMN2为NULL,它应该从COLUMN3检查相同的变量,如果两者都为null,它应该获得所有记录。



我们可以把这个链接作为你的参考完全理解



[]

解决方案

Hi all,

i have a query which have multiple search options and i have apply the query something like this


SELECT * FROM TABLE WHERE 

((TABLE.COLUMN1 IS NULL OR TABLE.COLUMN1=0) AND (@variable1 IS NULL OR @variable1=0)
OR TABLE.COLUMN1= CASE WHEN ((@variable1=0) OR (@variable1 IS NULL))
THEN TABLE.COLUMN1 ELSE @variable1 END)

AND 

((TABLE.COLUMN2 IS NULL OR TABLE.COLUMN2=0) AND (@variable2 IS NULL OR @variable2=0)
OR TABLE.COLUMN2= CASE WHEN ((@variable2=0) OR (@variable2 IS NULL))
THEN TABLE.COLUMN2 ELSE @variable2 END)



now my issue is for column2 i need to check the same thing with two different columns. "COLUMN2" and "COLUMN3". if COLUMN2 is NULL it should check from COLUMN3 for same variable and if both are null it should get all the records.

we can take this link as a ref for your full understanding

https://ask.sqlservercentral.com/questions/15758/query-with-optional-parameters.html[^]

解决方案


这篇关于如何通过两列过滤数据进行全文搜索sql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 23:24