Click here to Skip to main content
15,908,834 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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%' or b.BusinessName LIKE '%d%' or b.BusinessDescription LIKE '%d%'



Hi all
#1)How to create stored procedure for above sql command
#2)How to pass different value on '%d%' on above code ( d should b user keyword like google textbox)
#3)How to call above code on MVC4??

can u help me ??
Posted
Comments
Andy Lanng 17-Aug-15 6:46am    
do you google?
Sanket Saxena 17-Aug-15 6:47am    
suggest you to do google first...

Try:
SQL
CREATE PROCEDURE DoMySelect
    @SEARCH NVARCHAR(100)
AS
BEGIN
    SET NOCOUNT ON;
    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 '%' + @SEARCH + '%'
       OR b.BusinessName LIKE '%' + @SEARCH + '%'
       OR b.BusinessDescription LIKE '%' + @SEARCH + '%'
END
GO
 
Share this answer
 
Comments
Member 11367931 17-Aug-15 23:48pm    
But some records are not displaying..
if i type a keyword
it will return all records that match from tblBusinessCategory(BusinessCategory , BusinessName , BusinessDescription) is that right ??
OriginalGriff 18-Aug-15 4:40am    
So look at what it is returning, and the row you expect.
Is there any common factor?
We can;t help on that, because we don't have access to your data!
Member 11367931 18-Aug-15 6:20am    
thnks.. thts my fault.. lol thtz right :)
OriginalGriff 18-Aug-15 6:37am    
You're welcome!
In addition to solution 1 by OriginalGriff[^], here's another option accordingly to your requirements:

SQL
CREATE PROCEDURE DoMySelect
    @bc NVARCHAR(100), 
    @bn NVARCHAR(100),
    @bd NVARCHAR(100)
AS
BEGIN
    SET NOCOUNT ON;
    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 '%' + @bc + '%'
       OR b.BusinessName LIKE '%' + @bn + '%'
       OR b.BusinessDescription LIKE '%' + @bd + '%'
END
GO


For further information, please see:
CREATE PROCEDURE[^]
Getting Started with Entity Framework 4.0 Database First and ASP.NET 4 Web Forms - Part 7 - using stored procedures[^]
How To Call Stored Procedure In MVC4 ASP.NET C#[^]
 
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