USE [CmxSystem]
GO
/****** Object: UserDefinedFunction [dbo].[Fun_GetCarBaseInfo] Script Date: 2018/10/7 17:03:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[Fun_GetCarBaseInfo]
(
@BrandId int,
@SeriesID int,
@CarsType int,
@EntId int
)
RETURNS TABLE
AS
RETURN
(
--库存表和车俩信息表
with cte as
(
select detm.*,car.BrandID,car.CarsType,car.SeriesID from WarehouseStockDetm detm
left join CarBaseInfo car
on detm.CarsVin=car.CarsVin
where detm.Status=2 and detm.ZhiyaStatus!=1
),
--申贷从表和申贷主表
appcte as
(
select line.* from FinancialCreditCarApplyheader header
left join FinancialCreditCarApplyLine line
on line.QcNO=header.QcNO
where header.Status=0 and header.EntId=@EntId
and line.BrandID=@BrandId and line.CarsType=@CarsType and line.SeriesID=@SeriesID
)
-- 库存和申贷连接
select app.QcNO,c.CarsV
SQL 2016 新语法 函数 和 with cte as() 结合使用案例
最新推荐文章于 2021-07-14 09:33:01 发布
本文介绍了SQL Server 2016中新的语法特性,重点讲解了如何将函数与Common Table Expression (CTE) `WITH cte AS()` 结合使用,通过实例解析来展示这种组合在数据处理和查询优化上的优势。
摘要由CSDN通过智能技术生成