怎么创建带参数的视图,项目里面刚开始创建存储过程,后来想改成视图。
ALTER PROCEDURE [dbo].[GetNrequestItemByNFNo]
@nrequestformno varchar(100)
AS
SELECT
NRequestItemno
,[ItemSource]
,[NRequestFormNo]
,[BarCodeFormNo]
,[TollItemNo]
,[formno]
,[ParItemNo]
,(select cname from testitem where itemno=a.paritemno) as itemnamecw
,(select orderno from testitem where itemno=a.paritemno) as orderno
FROM dbo.NRequestItem a
where nrequestformno=@nrequestformno
怎么添加视图。
[解决办法]
视图不可以带参数,以你的要求,分两步走:先建视图,再用存储过程调用
create view vie_NRequestItem
as
SELECT
NRequestItemno
,[ItemSource]
,[NRequestFormNo]
,[BarCodeFormNo]
,[TollItemNo]
,[formno]
,[ParItemNo]
,(select cname from testitem where itemno=a.paritemno) as itemnamecw
,(select orderno from testitem where itemno=a.paritemno) as orderno
FROM dbo.NRequestItem
ALTER PROCEDURE [dbo].[GetNrequestItemByNFNo]
@nrequestformno varchar(100)
AS
SELECT *
FROM vie_NRequestItem a
where nrequestformno=@nrequestformno
go