Click here to Skip to main content
15,895,779 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
select * from tblBusinessCategory as b
inner join tblUser as u
on b.BusinessID=u.BusinessCategoryId
inner join tblAddress as a
on u.AddressId=a.AddressID
where u.BusinessCategoryId in (select BusinessCategory from tblBusinessCategory where BusinessCategory LIKE '%d%')






While doing this query i got

#1 ) Conversion failed when converting the nvarchar value 'Dentist' to data type int. how to solve this ??
#2 ) How to perform like operation on multiple columns??
#3 ) Is this possible to call this query in mvc4 controller ??
Posted

1 solution

Why to use subquery to filter data, if you can use a "condition" directly?!?

SQL
select *
from tblBusinessCategory as b
    inner join tblUser as u on b.BusinessID=u.BusinessCategoryId
    inner join tblAddress as a on u.AddressId=a.AddressID
where b.BusinessCategory LIKE '%d%'


Please, take a look at this excellent article: Visual Representation of SQL Joins[^] to understand how join's work.

#1 ) Conversion failed when converting the nvarchar value 'Dentist' to data type int. how to solve this ??
BusinessCategoryId is not the same as BusinessCategory. To be able to get proper data, you have to write:
SQL
where u.BusinessCategoryId in (select BusinessCategoryId from tblBusinessCategory where BusinessCategory LIKE '%d%')

But! I do not recommend to use subquery like this, because of performance issue!

#2 ) How to perform like operation on multiple columns??
Write proper WHERE statement!
SQL
WHERE ((Column1 Like '%a' AND (Column2 = 1 OR Column3 = 2)


#3 ) Is this possible to call this query in mvc4 controller ??
I do not understand you... ;(
 
Share this answer
 
Comments
Member 11367931 17-Aug-15 6:04am    
thanks sir..
#3 ) am doing project in mvc sir.. i want to implement this query on mvc4.. do u have any idea sir ?
Maciej Los 17-Aug-15 6:41am    
Sorry, but don't get you. If you mean you want to call sql query, please have a look here: http://stackoverflow.com/questions/16898050/how-to-use-old-style-sql-in-mvc4. As a standard is to use Entity Framework.
Member 11367931 17-Aug-15 6:46am    
thanks you sir

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