SQL 2016 新语法 函数 和 with cte as() 结合使用案例

本文介绍了SQL Server 2016中新的语法特性,重点讲解了如何将函数与Common Table Expression (CTE) `WITH cte AS()` 结合使用,通过实例解析来展示这种组合在数据处理和查询优化上的优势。
摘要由CSDN通过智能技术生成
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值