Click here to Skip to main content
15,918,333 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
my following query is giving wrong results.how can i correct it.

SQL
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..
Posted
Updated 18-Dec-13 18:59pm
v2

1 solution

Try this:
SQL
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


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.

SQL
SELECT CONCAT(partyname, ',  ', Contact_person) as [Contact name]...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900