在运算符和条件中使用多个 [英] using multiple in operators with and conditions

查看:84
本文介绍了在运算符和条件中使用多个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的以下查询给出了错误的结果。我可以更正它。



my following query is giving wrong results.how can i correct it.

select (partyname + ' ' + ',' + '  ' + Contact_person) as name, (mobile + ' '+','+'  '+Email + ' '+','+'  ' + phone) as contactdetails,Address,(City + ' '+','+'  '+ Area) as city_area, Status,CallType,Visit_time,visit_purpose,Interaction,Already_Computer,Software,area
  FROM [CallRegister].[dbo].[MarketingCall] where Status in('')or City in('') or Area in('') or  Software in('') or CallType in('')





我希望每个条件都满足,如果它有一些值并过滤根据它的行如果状态和城市有一些值,它应该只根据这个标准过滤。我应该使用和操作员。



帮助我..



I want every in condition to be satisfied if it has some values and filter the rows according to itLike if "status" and "city" has some values it should filter only on this criteria.Should i use and operator.

help me..

推荐答案

试试这个:

Try this:
SELECT (partyname + ' ' + ',' + '  ' + Contact_person) as [Contact name], (mobile + ' '+','+'  '+Email + ' '+','+'  ' + phone) as [Contact details], Address, (City + ' ' + ', ' + '  '+ Area) as [city area], Status, CallType, Visit_time, visit_purpose, Interaction, Already_Computer, Software, area
FROM [CallRegister].[dbo].[MarketingCall]
WHERE [Status] = @status AND City = @city





有关构建搜索条件的详细信息,请参阅: WHERE(T-SQL) [ ^ ]



或者,您可以构建动态查询 [ ^ ]。br />


顺便说一下:而不是使用 + operator [ ^ ]我建议使用 CONCAT [ ^ ]功能。





For further information about building search criteria, please see: WHERE (T-SQL)[^]

Alternatively, yoou can build dynamic queries[^].

By the Way: rather than using + operator[^] i would suggest to use CONCAT[^] function.

SELECT CONCAT(partyname, ',  ', Contact_person) as [Contact name]...


这篇关于在运算符和条件中使用多个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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