我是SQL的新手查询者,但我可以做一点工作,并且了解一些概念。我正在尝试编辑旧的IT经理编写的存储过程,但是不确定如何使用WITH
语句。到目前为止,这是我要尝试的CREATE
一个新的存储过程。
*USE [WYN]
GO
/****** Object: StoredProcedure [dbo].[wynne_insurance_census_report] Script Date: 9/12/2018 10:20:45 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE proc [dbo].[wynne_insurance_census_report] @DATEIN VARCHAR(8)
AS
with cte_emp (emp, nam, ssc, gen, brt, hd)
as
(SELECT a.EMPLOYID, rtrim(LASTNAME) + ', ' + rtrim(FRSTNAME), SOCSCNUM, GENDER, BRTHDATE, b.BENEFIT
from UPR00100 a left join UPR00600 b on a.EMPLOYID = b.EMPLOYID
where a.INACTIVE = '0' and b.INACTIVE = '0'
)
select nam, ssc,
case
when gen = '1' then 'Male'
else 'Female'
end,
brt,
zip,
hd,
--Coverage Tier
(select BENEFIT
from upr00600) Coverage
order by 1*