sql MS SQL表值函数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql MS SQL表值函数相关的知识,希望对你有一定的参考价值。

CREATE FUNCTION dbo.GetProductsByCategory (@CategoryID INT)
RETURNS TABLE
AS
    RETURN
    (SELECT P.ProductID,
          P.Name   AS ProductName,
          P.ProductNumber,
          P.ListPrice,
          PC.Name  AS Category,
          PSC.Name AS SubCategory
    FROM  Production.Product P
          INNER JOIN Production.ProductSubcategory PSC
            ON P.ProductSubcategoryID = PSC.ProductSubcategoryID
          INNER JOIN Production.ProductCategory PC
            ON PSC.ProductCategoryID = PC.ProductCategoryID
    WHERE  P.ProductSubcategoryID IS NOT NULL
          AND PC.ProductCategoryID = @CategoryID) 

-- EXECUTION
SELECT ProductName, ProductNumber, SubCategory 
     FROM dbo.GetProductsByCategory(1);

以上是关于sql MS SQL表值函数的主要内容,如果未能解决你的问题,请参考以下文章

PCB MS SQL表值函数与CLR 表值函数 (例:字符串分割转表)

PCB MS SQL 将字符串分割为表变量(表值函数)

sql2005中 表值函数是啥

sql2005中 表值函数是啥

PCB MS SQL CLR聚合函数(函数作用,调用顺序,调用次数) CLR说明

sql [sql]表值函数示例2