1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16:
SELECT DISTINCT TOP 100 PERCENT VW_HPPATMFL.ccGrpName, VW_HPPATMFL.PPPATno, VW_HPPATMFL.PPBLDT, VW_HPPATMFL.PPADDT, VW_HPPATMFL.PPDSDT, HAABSTFL.AALOSD, VW_HPPATMFL.PPNAME, HPMEDRFL.PMPSSN, VW_HPPATMFL.PPTYPE, VW_HPPATMFL.PPMSRV, VW_HPPATMFL.PPFNCL + ' ' + HBFNCLFL.BNNAME AS FC_Desc, HPINPLFL.PLINCO, HPINCOFL.PINAME, HPINPLFL.PLPLCY, VW_HPPATMFL.PPPDOB, VW_HPPATMFL.PPCHGS, VW_HPPATMFL.PPADJU, VW_HPPATMFL.PPPYMT, VW_HPPATMFL.PPCBAL, HPINPLFL.PLPLN# FROM HAABSTFL LEFT OUTER JOIN HBFNCLFL RIGHT OUTER JOIN VW_HPPATMFL ON HBFNCLFL.BNGRP# = VW_HPPATMFL.PPGRPno AND HBFNCLFL.BNFNCL = VW_HPPATMFL.PPFNCL LEFT OUTER JOIN HPINPLFL INNER JOIN HPINCOFL ON HPINPLFL.PLINCO = HPINCOFL.PICMP# ON VW_HPPATMFL.PPGRPno = HPINPLFL.PLGRP# AND VW_HPPATMFL.PPPATno = HPINPLFL.PLPAT# AND VW_HPPATMFL.PPGRPno = HPINCOFL.PIGRP# LEFT OUTER JOIN HPMEDRFL ON VW_HPPATMFL.PPGRPno = HPMEDRFL.PMGRP# AND VW_HPPATMFL.PPPATno = HPMEDRFL.PMPAT# ON HAABSTFL.AAGRP# = VW_HPPATMFL.PPGRPno AND HAABSTFL.AAPAT# = VW_HPPATMFL.PPPATno WHERE (VW_HPPATMFL.PPFNCL = @PPFNCL) AND (VW_HPPATMFL.PPDSDT BETWEEN @StartDate AND @EndDate) AND (HPINPLFL.PLPLN# = 1) AND (VW_HPPATMFL.ccGrpName = @GRPNAME)
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30:
CREATE FUNCTION dbo.Split ( @RowData nvarchar(2000), @SplitOn nvarchar(5) ) RETURNS @RtnValue table ( Id int identity(1,1), Data nvarchar(100) ) AS BEGIN Declare @Cnt int Set @Cnt = 1 While (Charindex(@SplitOn,@RowData)>0) Begin Insert Into @RtnValue (data) Select Data = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1))) Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData)) Set @Cnt = @Cnt + 1 End Insert Into @RtnValue (data) Select Data = ltrim(rtrim(@RowData)) Return END