从sp传递参数以查看

时间:2018-08-17 05:08:10

标签: view sql-server-2012

我在存储过程中使用以下查询。

F_Chem_nameLanguage是输入参数。

是否可以为此查询创建一个视图,并将这些输入参数从存储过程传递给该视图?

如何传递参数以从存储过程中查看?

WITH CTE AS
(
SELECT F_PRODUCT
      ,n.F_CAS_NUMBER
      ,c.F_COMPONENT_ID
FROM dbo.PDF_MSDS

    CROSS APPLY (SELECT value as F_CAS_NUMBER
                 FROM STRING_SPLIT(F_CAS_NUMBERS, '¿')
                 WHERE value <> '') as n

    CROSS APPLY (SELECT value as F_COMPONENT_ID
                 FROM STRING_SPLIT(F_COMPONENT_IDS, '¿')
                 WHERE value <> '') as c
)
SELECT CTE.F_PRODUCT
      ,COM.F_Cas_Number
      ,COM.F_Component_Id
      ,COM.F_Chem_Name
FROM dbo.Components COM

    INNER JOIN CTE
        ON CTE.F_CAS_NUMBER = COM.F_Cas_Number
            AND CTE.F_COMPONENT_ID = COM.F_Component_Id

WHERE COM.F_Chem_Name LIKE @Chem_Name
    AND Language = @Language 

1 个答案:

答案 0 :(得分:1)

您的选择是:

1)创建没有WHERE子句的视图,并在从视图中选择时在proc中指定WHERE子句

2)将视图转换为table-valued function,并将值作为参数传递。