Rumah >pangkalan data >tutorial mysql >简单的存储过程的使用

简单的存储过程的使用

WBOY
WBOYasal
2016-06-07 16:01:44938semak imbas

创建存储过程: USE [AIS20140417092531] GO /****** Object: StoredProcedure [dbo].[HBSH_MS_BillType_in_ofmine] Script Date: 09/01/2014 14:34:24 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].[HBSH_MS_BillType

创建存储过程:

USE [AIS20140417092531]
GO
/****** Object: StoredProcedure [dbo].[HBSH_MS_BillType_in_ofmine] Script Date: 09/01/2014 14:34:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[HBSH_MS_BillType_in_ofmine]
-- Add the parameters for the stored procedure here
@type varchar(20) --添加查询条件参数
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;


-- Insert statements for procedure here
--创建临时表,存放膜,胶供应商名称
CREATE TABLE #temp(

ID INT IDENTITY(1,1),
Name VARCHAR(50),
FType INT

)

INSERT INTO #temp
(
-- ID -- this column value is auto-generated
NAME,
FType


)

(
SELECT ts.FName,200
FROM t_Supplier ts
)

INSERT INTO #temp
(
-- ID -- this column value is auto-generated
NAME,FType
)
(
SELECT ts.FName,200 FROM AIS20140417092652.dbo.t_Supplier ts
)

INSERT INTO #temp
(
-- ID -- this column value is auto-generated
Name,
FType
)
VALUES
(
'河北智能',
200
)

INSERT INTO #temp
(
-- ID -- this column value is auto-generated
Name,
FType
)

(
SELECT to1.FName,201 FROM t_Organization to1
)

INSERT INTO #temp
(
-- ID -- this column value is auto-generated
Name,
FType
)

(
SELECT to1.FName,201 FROM AIS20140417092652.dbo.t_Organization to1
)

INSERT INTO #temp
(
-- ID -- this column value is auto-generated
Name,
FType
)

(
SELECT hmc.fname,hmc.ftype FROM AcctCommerce.dbo.HBSH_MS_CustomName hmc
)

SELECT t.Name,t.FType FROM #temp t where t.ftype=@type GROUP BY t.Name,t.FType

END

---执行添加条件内容

exec [HBSH_MS_BillType_in_ofmine] ' ' --单引号当中直接添加筛选的条件内容

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn