查询有关动态用户输入的搜索记录 [英] Query for searching records on dynamic user input

查看:100
本文介绍了查询有关动态用户输入的搜索记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想动态实现搜索,
例如我有5个控件,c1是文本框,c2是下拉列表,c3,c4,c5是日期
基本查询是从abc中选择*
如果c1中有数据,则将其添加到查询的where子句中,否则保留.
如果c2中有数据,则将其添加到查询的where子句中,否则保留.
如果c3中有数据,则将其添加到查询的where子句中,否则保留.
如果c4和c5中有数据,则将其添加到查询的where子句中,作为c4和c5之间的日期,否则离开.
用户可以给出从c1到c5的任何值,从而根据我要建立查询的条件(我必须建立适当的where子句)
我如何在SQL Server中执行它.

I want to implement searching dynamically,
for eg. I have 5 controls c1 is textbox, c2 is dropdownlists and c3,c4,c5 are dates
basic query is select * from abc
if there is data in c1 then add it to query’s where clause, else leave.
if there is data in c2 then add it to query’s where clause, else leave.
if there is data in c3 then add it to query’s where clause, else leave.
if there is data in c4 and c5 then add it to query’s where clause as date between c4 and c5, else leave.
User can give any value from c1 to c5 thus according to that i want to build query (i have to build proper where clause)
How do i perform it in SQL-server.

推荐答案

我认为 ^ ]的文章中有您的答案.
I think that this[^] article has your answer.


您可以将它们全部添加到查询中并使用LIKE,也可以使用或,例如(txt1 = @val或LEN(@val)== 0).我曾经通过仅使用或忽略任何空的搜索词来进行非常复杂的搜索.我没有使用字符串类的Trim方法来传递仅是空格的任何字符串.
You can add them all to the query and use LIKE, you can also use an or as in if (txt1 = @val or LEN(@val) == 0). I once did a pretty complex search by just using or to ignore any search terms that were empty. I used the Trim method of the string class to not be passed any strings that were just whitespace.


这篇关于查询有关动态用户输入的搜索记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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