存储过程根据字段的某个特定值来显示这一条记录
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Pr_GetDocuments]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[Pr_GetDocuments]
AS
SELECT
Document.*,Staff.RealName
FROM
Document
INNER JOIN
Staff
ON
Staff.Staff_ID = UserID and show='yes'
'
END
就是想显示show这列里面值为yes的所有记录。
------解决方案--------------------
SQL code
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Pr_GetDocuments]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[Pr_GetDocuments]
AS
SELECT
Document.*,Staff.RealName
FROM
Document
INNER JOIN
Staff
ON
Staff.Staff_ID = UserID and show=''yes''
'
END