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
怎么添加视图。

解决方案 »

  1.   

    视图不可以带参数,以你的要求,分两步走:先建视图,再用存储过程调用
    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.NRequestItemALTER PROCEDURE [dbo].[GetNrequestItemByNFNo]
    @nrequestformno varchar(100)
    AS
    SELECT *
    FROM vie_NRequestItem a 
    where nrequestformno=@nrequestformno
    go