如何编写存储过程? [英] How to write stored procedure ?

查看:94
本文介绍了如何编写存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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%'







大家好

#1)如何为上面的sql命令创建存储过程

#2)如何在上面的代码上传递'%d%'上的不同值(d应该像谷歌文本框那样用户关键字)

#3)如何在MVC4上调用上面的代码??



你可以帮我吗??




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 ??

推荐答案

试试:

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


除了 OriginalGriff [ ^ ],这是根据您的要求提供的另一个选项:



In addition to solution 1 by OriginalGriff[^], here's another option accordingly to your requirements:

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





如需了解更多信息,请请参阅:

创建程序 [ ^ ]

实体入门Framework 4.0数据库优先和ASP.NET 4 Web表单 - 第7部分 - 使用存储过程 [ ^ ]

如何调用存储过程MVC4 ASP.NET C# [ ^ ]



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#[^]


这篇关于如何编写存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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