DBA Data[Home] [Help]

APPS.PSB_WS_YEAR_TOTAL SQL Statements

The following lines contain the word 'select', 'insert', 'update' or 'delete':

Line: 79

    p_spkg_selection_exists      VARCHAR2,
    p_spkg_name                  VARCHAR2,
    p_flexfield_low              VARCHAR2,
    p_flexfield_high             VARCHAR2,
    p_flexfield_delimiter        VARCHAR2,
    p_chart_of_accounts          NUMBER,
    p_flex_value                 VARCHAR2,
    p1_amount            OUT  NOCOPY     NUMBER,
    p2_amount            OUT  NOCOPY     NUMBER,
    p3_amount            OUT  NOCOPY     NUMBER,
    p4_amount            OUT  NOCOPY     NUMBER,
    p5_amount            OUT  NOCOPY     NUMBER,
    p6_amount            OUT  NOCOPY     NUMBER,
    p7_amount            OUT  NOCOPY     NUMBER,
    p8_amount            OUT  NOCOPY     NUMBER,
    p9_amount            OUT  NOCOPY     NUMBER,
    p10_amount           OUT  NOCOPY     NUMBER,
    p11_amount           OUT  NOCOPY     NUMBER,
    p12_amount           OUT  NOCOPY     NUMBER
  ) IS
  --

/* Bug 3331024 Removed Rule hint */
    cursor c_sum_all is
      select NVL(SUM(column1),0)  A, NVL(SUM(column2),0)  B, NVL(SUM(column3),0)  C, NVL(SUM(column4),0)  D,
	     NVL(SUM(column5),0)  E, NVL(SUM(column6),0)  F, NVL(SUM(column7),0)  G, NVL(SUM(column8),0)  H,
	     NVL(SUM(column9),0)  I, NVL(SUM(column10),0) J, NVL(SUM(column11),0) K, NVL(SUM(column12),0) L,
	     DECODE(UPPER(account_type),'L','I','O','I','R','I','C','I','A','E','E') account_type
	FROM PSB_WS_YEAR_AMOUNTS_V  WYA
       WHERE worksheet_id = p_worksheet_id
       -- Changed reference to 'T' from 'C' for All accounts for bug 3191611
	 AND (p_account_flag = 'T' OR account_type = p_account_flag
	 OR account_type = DECODE(p_account_flag,'P','R','~')
	 OR account_type = DECODE(p_account_flag,'P','E','~')
	 OR account_type = DECODE(p_account_flag,'N','A','~')
	 OR account_type = DECODE(p_account_flag,'N','L','~')
	 OR account_type = DECODE(p_account_flag,'B','C','~')
	 OR account_type = DECODE(p_account_flag,'B','D','~'))
	 AND ((p_currency_flag = 'C' AND currency_code <> 'STAT')
	 OR (p_currency_flag = 'S' AND currency_code = 'STAT'))
	 AND ((p_template_id is NULL AND template_id is null) OR (p_template_id is NOT NULL AND template_id = p_template_id))
/* Bug No 2543015 Start */
	 AND (p_spkg_flag = 'A'
		OR (p_spkg_selection_exists = 'N'
			AND service_package_id IN
				(SELECT sp.service_package_id
				   FROM PSB_SERVICE_PACKAGES sp, PSB_WORKSHEETS w
				  WHERE sp.global_worksheet_id = nvl(w.global_worksheet_id, w.worksheet_id)
				    AND w.worksheet_id = p_worksheet_id
				    AND sp.name like p_spkg_name))
		OR (p_spkg_selection_exists = 'Y'
			AND service_package_id IN
				(SELECT service_package_id
				   FROM PSB_WS_SERVICE_PKG_PROFILES_V
				  WHERE worksheet_id = p_profile_worksheet_id
				    AND ((user_id =  p_user_id) or (p_user_id is null and user_id is null))
				    AND service_package_name like decode(p_spkg_name, '%', service_package_name, p_spkg_name))))
/* Bug No 2543015 End */
      GROUP by DECODE(UPPER(account_type),'L','I','O','I','R','I','C','I','A','E','E');
Line: 141

      select  NVL(SUM(column1),0)  A, NVL(SUM(column2),0)  B, NVL(SUM(column3),0)  C, NVL(SUM(column4),0)  D,
	     NVL(SUM(column5),0)  E, NVL(SUM(column6),0)  F, NVL(SUM(column7),0)  G, NVL(SUM(column8),0)  H,
	     NVL(SUM(column9),0)  I, NVL(SUM(column10),0) J, NVL(SUM(column11),0) K, NVL(SUM(column12),0) L,
	     DECODE(UPPER(account_type),'L','I','O','I','R','I','C','I','A','E','E') account_type
	FROM PSB_WS_YEAR_AMOUNTS_V  WYA
       WHERE worksheet_id = p_worksheet_id
       -- Changed reference to 'T' from 'C' for All accounts for bug 3191611
	 AND (p_account_flag = 'T' OR account_type = p_account_flag
	        OR account_type = DECODE(p_account_flag,'P','R','~')
		OR account_type = DECODE(p_account_flag,'P','E','~')
		OR account_type = DECODE(p_account_flag,'N','A','~')
		OR account_type = DECODE(p_account_flag,'N','L','~')
		OR account_type = DECODE(p_account_flag,'B','C','~')
		OR account_type = DECODE(p_account_flag,'B','D','~'))
	        AND ((p_currency_flag = 'C' AND currency_code <> 'STAT')
		OR (p_currency_flag = 'S' AND currency_code = 'STAT'))
	        AND ((p_template_id is NULL AND template_id is null)
		OR (p_template_id is NOT NULL AND template_id = p_template_id))
/* Bug No 2543015 Start */
	 AND (p_spkg_flag = 'A'
		OR (p_spkg_selection_exists = 'N'
			AND service_package_id IN
				(SELECT sp.service_package_id
				   FROM PSB_SERVICE_PACKAGES sp, PSB_WORKSHEETS w
				  WHERE sp.global_worksheet_id = nvl(w.global_worksheet_id, w.worksheet_id)
				    AND w.worksheet_id = p_worksheet_id
				    AND sp.name like p_spkg_name))
		OR (p_spkg_selection_exists = 'Y'
			AND service_package_id IN
				(SELECT service_package_id
				   FROM PSB_WS_SERVICE_PKG_PROFILES_V
				  WHERE worksheet_id = p_profile_worksheet_id
				    AND ((user_id =  p_user_id) or (p_user_id is null and user_id is null))
				    AND service_package_name like decode(p_spkg_name, '%', service_package_name, p_spkg_name))))
/* Bug No 2543015 End */
	 AND EXISTS
	    (select 1 from gl_code_combinations
	      where code_combination_id = WYA.code_combination_id
		and chart_of_accounts_id = p_chart_of_accounts
		and ( (segment1 is null) or (g_segment_low(1) is null and g_segment_high(1) is null) or (g_segment_low(1) is null and segment1 <= g_segment_high(1)) or (g_segment_high(1) is null and segment1 >= g_segment_low(1)) or
			(g_segment_low(1) = 'LK' and segment1 like g_segment_high(1)) or (g_segment_low(1) is not null and g_segment_high(1) is not null and g_segment_low(1) <> 'LK' and segment1 between g_segment_low(1) and g_segment_high(1)) )
		and ( (segment2 is null) or (g_segment_low(2) is null and g_segment_high(2) is null) or (g_segment_low(2) is null and segment2 <= g_segment_high(2)) or (g_segment_high(2) is null and segment2 >= g_segment_low(2)) or
			(g_segment_low(2) = 'LK' and segment2 like g_segment_high(2)) or (g_segment_low(2) is not null and g_segment_high(2) is not null and g_segment_low(2) <> 'LK' and segment2 between g_segment_low(2) and g_segment_high(2)) )
		and ( (segment3 is null) or (g_segment_low(3) is null and g_segment_high(3) is null) or (g_segment_low(3) is null and segment3 <= g_segment_high(3)) or (g_segment_high(3) is null and segment3 >= g_segment_low(3)) or
			(g_segment_low(3) = 'LK' and segment3 like g_segment_high(3)) or (g_segment_low(3) is not null and g_segment_high(3) is not null and g_segment_low(3) <> 'LK' and segment3 between g_segment_low(3) and g_segment_high(3)) )
		and ( (segment4 is null) or (g_segment_low(4) is null and g_segment_high(4) is null) or (g_segment_low(4) is null and segment4 <= g_segment_high(4)) or (g_segment_high(4) is null and segment4 >= g_segment_low(4)) or
			(g_segment_low(4) = 'LK' and segment4 like g_segment_high(4)) or (g_segment_low(4) is not null and g_segment_high(4) is not null and g_segment_low(4) <> 'LK' and segment4 between g_segment_low(4) and g_segment_high(4)) )
		and ( (segment5 is null) or (g_segment_low(5) is null and g_segment_high(5) is null) or (g_segment_low(5) is null and segment5 <= g_segment_high(5)) or (g_segment_high(5) is null and segment5 >= g_segment_low(5)) or
			(g_segment_low(5) = 'LK' and segment5 like g_segment_high(5)) or (g_segment_low(5) is not null and g_segment_high(5) is not null and g_segment_low(5) <> 'LK' and segment5 between g_segment_low(5) and g_segment_high(5)) )
		and ( (segment6 is null) or (g_segment_low(6) is null and g_segment_high(6) is null) or (g_segment_low(6) is null and segment6 <= g_segment_high(6)) or (g_segment_high(6) is null and segment6 >= g_segment_low(6)) or
			(g_segment_low(6) = 'LK' and segment6 like g_segment_high(6)) or (g_segment_low(6) is not null and g_segment_high(6) is not null and g_segment_low(6) <> 'LK' and segment6 between g_segment_low(6) and g_segment_high(6)) )
		and ( (segment7 is null) or (g_segment_low(7) is null and g_segment_high(7) is null) or (g_segment_low(7) is null and segment7 <= g_segment_high(7)) or (g_segment_high(7) is null and segment7 >= g_segment_low(7)) or
			(g_segment_low(7) = 'LK' and segment7 like g_segment_high(7)) or (g_segment_low(7) is not null and g_segment_high(7) is not null and g_segment_low(7) <> 'LK' and segment7 between g_segment_low(7) and g_segment_high(7)) )
		and ( (segment8 is null) or (g_segment_low(8) is null and g_segment_high(8) is null) or (g_segment_low(8) is null and segment8 <= g_segment_high(8)) or (g_segment_high(8) is null and segment8 >= g_segment_low(8)) or
			(g_segment_low(8) = 'LK' and segment8 like g_segment_high(8)) or (g_segment_low(8) is not null and g_segment_high(8) is not null and g_segment_low(8) <> 'LK' and segment8 between g_segment_low(8) and g_segment_high(8)) )
		and ( (segment9 is null) or (g_segment_low(9) is null and g_segment_high(9) is null) or (g_segment_low(9) is null and segment9 <= g_segment_high(9)) or (g_segment_high(9) is null and segment9 >= g_segment_low(9)) or
			(g_segment_low(9) = 'LK' and segment9 like g_segment_high(9)) or (g_segment_low(9) is not null and g_segment_high(9) is not null and g_segment_low(9) <> 'LK' and segment9 between g_segment_low(9) and g_segment_high(9)) )
		and ( (segment10 is null) or (g_segment_low(10) is null and g_segment_high(10) is null) or (g_segment_low(10) is null and segment10 <= g_segment_high(10)) or (g_segment_high(10) is null and segment10 >= g_segment_low(10)) or
			(g_segment_low(10) = 'LK' and segment10 like g_segment_high(10)) or (g_segment_low(10) is not null and g_segment_high(10) is not null and g_segment_low(10) <> 'LK' and segment10 between g_segment_low(10) and g_segment_high(10)) )
		and ( (segment11 is null) or (g_segment_low(11) is null and g_segment_high(11) is null) or (g_segment_low(11) is null and segment11 <= g_segment_high(11)) or (g_segment_high(11) is null and segment11 >= g_segment_low(11)) or
			(g_segment_low(11) = 'LK' and segment11 like g_segment_high(11)) or (g_segment_low(11) is not null and g_segment_high(11) is not null and g_segment_low(11) <> 'LK' and segment11 between g_segment_low(11) and g_segment_high(11)) )
		and ( (segment12 is null) or (g_segment_low(12) is null and g_segment_high(12) is null) or (g_segment_low(12) is null and segment12 <= g_segment_high(12)) or (g_segment_high(12) is null and segment12 >= g_segment_low(12)) or
			(g_segment_low(12) = 'LK' and segment12 like g_segment_high(12)) or (g_segment_low(12) is not null and g_segment_high(12) is not null and g_segment_low(12) <> 'LK' and segment12 between g_segment_low(12) and g_segment_high(12)) )
		and ( (segment13 is null) or (g_segment_low(13) is null and g_segment_high(13) is null) or (g_segment_low(13) is null and segment13 <= g_segment_high(13)) or (g_segment_high(13) is null and segment13 >= g_segment_low(13)) or
			(g_segment_low(13) = 'LK' and segment13 like g_segment_high(13)) or (g_segment_low(13) is not null and g_segment_high(13) is not null and g_segment_low(13) <> 'LK' and segment13 between g_segment_low(13) and g_segment_high(13)) )
		and ( (segment14 is null) or (g_segment_low(14) is null and g_segment_high(14) is null) or (g_segment_low(14) is null and segment14 <= g_segment_high(14)) or (g_segment_high(14) is null and segment14 >= g_segment_low(14)) or
			(g_segment_low(14) = 'LK' and segment14 like g_segment_high(14)) or (g_segment_low(14) is not null and g_segment_high(14) is not null and g_segment_low(14) <> 'LK' and segment14 between g_segment_low(14) and g_segment_high(14)) )
		and ( (segment15 is null) or (g_segment_low(15) is null and g_segment_high(15) is null) or (g_segment_low(15) is null and segment15 <= g_segment_high(15)) or (g_segment_high(15) is null and segment15 >= g_segment_low(15)) or
			(g_segment_low(15) = 'LK' and segment15 like g_segment_high(15)) or (g_segment_low(15) is not null and g_segment_high(15) is not null and g_segment_low(15) <> 'LK' and segment15 between g_segment_low(15) and g_segment_high(15)) )
		and ( (segment16 is null) or (g_segment_low(16) is null and g_segment_high(16) is null) or (g_segment_low(16) is null and segment16 <= g_segment_high(16)) or (g_segment_high(16) is null and segment16 >= g_segment_low(16)) or
			(g_segment_low(16) = 'LK' and segment16 like g_segment_high(16)) or (g_segment_low(16) is not null and g_segment_high(16) is not null and g_segment_low(16) <> 'LK' and segment16 between g_segment_low(16) and g_segment_high(16)) )
		and ( (segment17 is null) or (g_segment_low(17) is null and g_segment_high(17) is null) or (g_segment_low(17) is null and segment17 <= g_segment_high(17)) or (g_segment_high(17) is null and segment17 >= g_segment_low(17)) or
			(g_segment_low(17) = 'LK' and segment17 like g_segment_high(17)) or (g_segment_low(17) is not null and g_segment_high(17) is not null and g_segment_low(17) <> 'LK' and segment17 between g_segment_low(17) and g_segment_high(17)) )
		and ( (segment18 is null) or (g_segment_low(18) is null and g_segment_high(18) is null) or (g_segment_low(18) is null and segment18 <= g_segment_high(18)) or (g_segment_high(18) is null and segment18 >= g_segment_low(18)) or
			(g_segment_low(18) = 'LK' and segment18 like g_segment_high(18)) or (g_segment_low(18) is not null and g_segment_high(18) is not null and g_segment_low(18) <> 'LK' and segment18 between g_segment_low(18) and g_segment_high(18)) )
		and ( (segment19 is null) or (g_segment_low(19) is null and g_segment_high(19) is null) or (g_segment_low(19) is null and segment19 <= g_segment_high(19)) or (g_segment_high(19) is null and segment19 >= g_segment_low(19)) or
			(g_segment_low(19) = 'LK' and segment19 like g_segment_high(19)) or (g_segment_low(19) is not null and g_segment_high(19) is not null and g_segment_low(19) <> 'LK' and segment19 between g_segment_low(19) and g_segment_high(19)) )
		and ( (segment20 is null) or (g_segment_low(20) is null and g_segment_high(20) is null) or (g_segment_low(20) is null and segment20 <= g_segment_high(20)) or (g_segment_high(20) is null and segment20 >= g_segment_low(20)) or
			(g_segment_low(20) = 'LK' and segment20 like g_segment_high(20)) or (g_segment_low(20) is not null and g_segment_high(20) is not null and g_segment_low(20) <> 'LK' and segment20 between g_segment_low(20) and g_segment_high(20)) )
		and ( (segment21 is null) or (g_segment_low(21) is null and g_segment_high(21) is null) or (g_segment_low(21) is null and segment21 <= g_segment_high(21)) or (g_segment_high(21) is null and segment21 >= g_segment_low(21)) or
			(g_segment_low(21) = 'LK' and segment21 like g_segment_high(21)) or (g_segment_low(21) is not null and g_segment_high(21) is not null and g_segment_low(21) <> 'LK' and segment21 between g_segment_low(21) and g_segment_high(21)) )
		and ( (segment22 is null) or (g_segment_low(22) is null and g_segment_high(22) is null) or (g_segment_low(22) is null and segment22 <= g_segment_high(22)) or (g_segment_high(22) is null and segment22 >= g_segment_low(22)) or
			(g_segment_low(22) = 'LK' and segment22 like g_segment_high(22)) or (g_segment_low(22) is not null and g_segment_high(22) is not null and g_segment_low(22) <> 'LK' and segment22 between g_segment_low(22) and g_segment_high(22)) )
		and ( (segment23 is null) or (g_segment_low(23) is null and g_segment_high(23) is null) or (g_segment_low(23) is null and segment23 <= g_segment_high(23)) or (g_segment_high(23) is null and segment23 >= g_segment_low(23)) or
			(g_segment_low(23) = 'LK' and segment23 like g_segment_high(23)) or (g_segment_low(23) is not null and g_segment_high(23) is not null and g_segment_low(23) <> 'LK' and segment23 between g_segment_low(23) and g_segment_high(23)) )
		and ( (segment24 is null) or (g_segment_low(24) is null and g_segment_high(24) is null) or (g_segment_low(24) is null and segment24 <= g_segment_high(24)) or (g_segment_high(24) is null and segment24 >= g_segment_low(24)) or
			(g_segment_low(24) = 'LK' and segment24 like g_segment_high(24)) or (g_segment_low(24) is not null and g_segment_high(24) is not null and g_segment_low(24) <> 'LK' and segment24 between g_segment_low(24) and g_segment_high(24)) )
		and ( (segment25 is null) or (g_segment_low(25) is null and g_segment_high(25) is null) or (g_segment_low(25) is null and segment25 <= g_segment_high(25)) or (g_segment_high(25) is null and segment25 >= g_segment_low(25)) or
			(g_segment_low(25) = 'LK' and segment25 like g_segment_high(25)) or (g_segment_low(25) is not null and g_segment_high(25) is not null and g_segment_low(25) <> 'LK' and segment25 between g_segment_low(25) and g_segment_high(25)) )
		and ( (segment26 is null) or (g_segment_low(26) is null and g_segment_high(26) is null) or (g_segment_low(26) is null and segment26 <= g_segment_high(26)) or (g_segment_high(26) is null and segment26 >= g_segment_low(26)) or
			(g_segment_low(26) = 'LK' and segment26 like g_segment_high(26)) or (g_segment_low(26) is not null and g_segment_high(26) is not null and g_segment_low(26) <> 'LK' and segment26 between g_segment_low(26) and g_segment_high(26)) )
		and ( (segment27 is null) or (g_segment_low(27) is null and g_segment_high(27) is null) or (g_segment_low(27) is null and segment27 <= g_segment_high(27)) or (g_segment_high(27) is null and segment27 >= g_segment_low(27)) or
			(g_segment_low(27) = 'LK' and segment27 like g_segment_high(27)) or (g_segment_low(27) is not null and g_segment_high(27) is not null and g_segment_low(27) <> 'LK' and segment27 between g_segment_low(27) and g_segment_high(27)) )
		and ( (segment28 is null) or (g_segment_low(28) is null and g_segment_high(28) is null) or (g_segment_low(28) is null and segment28 <= g_segment_high(28)) or (g_segment_high(28) is null and segment28 >= g_segment_low(28)) or
			(g_segment_low(28) = 'LK' and segment28 like g_segment_high(28)) or (g_segment_low(28) is not null and g_segment_high(28) is not null and g_segment_low(28) <> 'LK' and segment28 between g_segment_low(28) and g_segment_high(28)) )
		and ( (segment29 is null) or (g_segment_low(29) is null and g_segment_high(29) is null) or (g_segment_low(29) is null and segment29 <= g_segment_high(29)) or (g_segment_high(29) is null and segment29 >= g_segment_low(29)) or
			(g_segment_low(29) = 'LK' and segment29 like g_segment_high(29)) or (g_segment_low(29) is not null and g_segment_high(29) is not null and g_segment_low(29) <> 'LK' and segment29 between g_segment_low(29) and g_segment_high(29)) )
		and ( (segment30 is null) or (g_segment_low(30) is null and g_segment_high(30) is null) or (g_segment_low(30) is null and segment30 <= g_segment_high(30)) or (g_segment_high(30) is null and segment30 >= g_segment_low(30)) or
			(g_segment_low(30) = 'LK' and segment30 like g_segment_high(30)) or (g_segment_low(30) is not null and g_segment_high(30) is not null and g_segment_low(30) <> 'LK' and segment30 between g_segment_low(30) and g_segment_high(30)) ))
		GROUP BY DECODE(UPPER(account_type),'L','I','O','I','R','I','C','I','A','E','E');
Line: 384

  pselection_exists             varchar2,
  puser_id                      number,
  pchart_of_accounts_id         number,
  pspkg_name                    varchar2,
  pflex_value                   varchar2,
  ptcolumn1             OUT  NOCOPY     number,
  ptcolumn2             OUT  NOCOPY     number,
  ptcolumn3             OUT  NOCOPY     number,
  ptcolumn4             OUT  NOCOPY     number,
  ptcolumn5             OUT  NOCOPY     number,
  ptcolumn6             OUT  NOCOPY     number,
  ptcolumn7             OUT  NOCOPY     number,
  ptcolumn8             OUT  NOCOPY     number,
  ptcolumn9             OUT  NOCOPY     number,
  ptcolumn10            OUT  NOCOPY     number,
  ptcolumn11            OUT  NOCOPY     number,
  ptcolumn12            OUT  NOCOPY     number

 ) IS

/* Bug 3331024 Remove Rule Hint */
  cursor c_sum_all is
      select NVL(SUM(column1),0)  A, NVL(SUM(column2),0)  B, NVL(SUM(column3),0)  C, NVL(SUM(column4),0)  D,
	     NVL(SUM(column5),0)  E, NVL(SUM(column6),0)  F, NVL(SUM(column7),0)  G, NVL(SUM(column8),0)  H,
	     NVL(SUM(column9),0)  I, NVL(SUM(column10),0) J, NVL(SUM(column11),0) K, NVL(SUM(column12),0) L
	FROM PSB_WS_YEAR_POSITION_AMOUNTS_V  WYA
       WHERE worksheet_id = pworksheet_id
	 AND position_line_id = pposition_line_id
	 AND ((pcurrency_flag = 'C' AND currency_code <> 'STAT') OR (pcurrency_flag = 'S' AND currency_code = 'STAT'))
	 AND template_id is null
/* Bug No 2543015 Start */
	 AND (pservice_package_flag = 'A'
		OR (pselection_exists = 'N'
			AND service_package_id IN
				(SELECT sp.service_package_id
				   FROM PSB_SERVICE_PACKAGES sp, PSB_WORKSHEETS w
				  WHERE sp.global_worksheet_id = nvl(w.global_worksheet_id, w.worksheet_id)
				    AND w.worksheet_id = pworksheet_id
				    AND sp.name like pspkg_name))
		OR (pselection_exists = 'Y'
			AND service_package_id IN
				(SELECT service_package_id
				   FROM PSB_WS_SERVICE_PKG_PROFILES_V
				  WHERE worksheet_id = pprofile_worksheet_id
				    AND ((user_id =  puser_id) or (puser_id is null and user_id is null))
				    AND service_package_name like decode(pspkg_name, '%', service_package_name, pspkg_name))));
Line: 434

      select NVL(SUM(column1),0)  A, NVL(SUM(column2),0)  B, NVL(SUM(column3),0)  C, NVL(SUM(column4),0)  D,
	     NVL(SUM(column5),0)  E, NVL(SUM(column6),0)  F, NVL(SUM(column7),0)  G, NVL(SUM(column8),0)  H,
	     NVL(SUM(column9),0)  I, NVL(SUM(column10),0) J, NVL(SUM(column11),0) K, NVL(SUM(column12),0) L
	FROM PSB_WS_YEAR_POSITION_AMOUNTS_V  WYA
       WHERE worksheet_id = pworksheet_id
	 AND position_line_id = pposition_line_id
	 AND ((pcurrency_flag = 'C' AND currency_code <> 'STAT') OR (pcurrency_flag = 'S' AND currency_code = 'STAT'))
	 AND template_id is null
/* Bug No 2543015 Start */
	 AND (pservice_package_flag = 'A'
		OR (pselection_exists = 'N'
			AND service_package_id IN
				(SELECT sp.service_package_id
				   FROM PSB_SERVICE_PACKAGES sp, PSB_WORKSHEETS w
				  WHERE sp.global_worksheet_id = nvl(w.global_worksheet_id, w.worksheet_id)
				    AND w.worksheet_id = pworksheet_id
				    AND sp.name like pspkg_name))
		OR (pselection_exists = 'Y'
			AND service_package_id IN
				(SELECT service_package_id
				   FROM PSB_WS_SERVICE_PKG_PROFILES_V
				  WHERE worksheet_id = pprofile_worksheet_id
				    AND ((user_id =  puser_id) or (puser_id is null and user_id is null))
				    AND service_package_name like decode(pspkg_name, '%', service_package_name, pspkg_name))))
/* Bug No 2543015 End */
	 AND EXISTS
	    (select 1 from gl_code_combinations
	      where code_combination_id = WYA.code_combination_id
		and chart_of_accounts_id = pchart_of_accounts_id
		and ( (segment1 is null) or (g_segment_low(1) is null and g_segment_high(1) is null) or (g_segment_low(1) is null and segment1 <= g_segment_high(1)) or (g_segment_high(1) is null and segment1 >= g_segment_low(1)) or
			(g_segment_low(1) = 'LK' and segment1 like g_segment_high(1)) or (g_segment_low(1) is not null and g_segment_high(1) is not null and g_segment_low(1) <> 'LK' and segment1 between g_segment_low(1) and g_segment_high(1)) )
		and ( (segment2 is null) or (g_segment_low(2) is null and g_segment_high(2) is null) or (g_segment_low(2) is null and segment2 <= g_segment_high(2)) or (g_segment_high(2) is null and segment2 >= g_segment_low(2)) or
			(g_segment_low(2) = 'LK' and segment2 like g_segment_high(2)) or (g_segment_low(2) is not null and g_segment_high(2) is not null and g_segment_low(2) <> 'LK' and segment2 between g_segment_low(2) and g_segment_high(2)) )
		and ( (segment3 is null) or (g_segment_low(3) is null and g_segment_high(3) is null) or (g_segment_low(3) is null and segment3 <= g_segment_high(3)) or (g_segment_high(3) is null and segment3 >= g_segment_low(3)) or
			(g_segment_low(3) = 'LK' and segment3 like g_segment_high(3)) or (g_segment_low(3) is not null and g_segment_high(3) is not null and g_segment_low(3) <> 'LK' and segment3 between g_segment_low(3) and g_segment_high(3)) )
		and ( (segment4 is null) or (g_segment_low(4) is null and g_segment_high(4) is null) or (g_segment_low(4) is null and segment4 <= g_segment_high(4)) or (g_segment_high(4) is null and segment4 >= g_segment_low(4)) or
			(g_segment_low(4) = 'LK' and segment4 like g_segment_high(4)) or (g_segment_low(4) is not null and g_segment_high(4) is not null and g_segment_low(4) <> 'LK' and segment4 between g_segment_low(4) and g_segment_high(4)) )
		and ( (segment5 is null) or (g_segment_low(5) is null and g_segment_high(5) is null) or (g_segment_low(5) is null and segment5 <= g_segment_high(5)) or (g_segment_high(5) is null and segment5 >= g_segment_low(5)) or
			(g_segment_low(5) = 'LK' and segment5 like g_segment_high(5)) or (g_segment_low(5) is not null and g_segment_high(5) is not null and g_segment_low(5) <> 'LK' and segment5 between g_segment_low(5) and g_segment_high(5)) )
		and ( (segment6 is null) or (g_segment_low(6) is null and g_segment_high(6) is null) or (g_segment_low(6) is null and segment6 <= g_segment_high(6)) or (g_segment_high(6) is null and segment6 >= g_segment_low(6)) or
			(g_segment_low(6) = 'LK' and segment6 like g_segment_high(6)) or (g_segment_low(6) is not null and g_segment_high(6) is not null and g_segment_low(6) <> 'LK' and segment6 between g_segment_low(6) and g_segment_high(6)) )
		and ( (segment7 is null) or (g_segment_low(7) is null and g_segment_high(7) is null) or (g_segment_low(7) is null and segment7 <= g_segment_high(7)) or (g_segment_high(7) is null and segment7 >= g_segment_low(7)) or
			(g_segment_low(7) = 'LK' and segment7 like g_segment_high(7)) or (g_segment_low(7) is not null and g_segment_high(7) is not null and g_segment_low(7) <> 'LK' and segment7 between g_segment_low(7) and g_segment_high(7)) )
		and ( (segment8 is null) or (g_segment_low(8) is null and g_segment_high(8) is null) or (g_segment_low(8) is null and segment8 <= g_segment_high(8)) or (g_segment_high(8) is null and segment8 >= g_segment_low(8)) or
			(g_segment_low(8) = 'LK' and segment8 like g_segment_high(8)) or (g_segment_low(8) is not null and g_segment_high(8) is not null and g_segment_low(8) <> 'LK' and segment8 between g_segment_low(8) and g_segment_high(8)) )
		and ( (segment9 is null) or (g_segment_low(9) is null and g_segment_high(9) is null) or (g_segment_low(9) is null and segment9 <= g_segment_high(9)) or (g_segment_high(9) is null and segment9 >= g_segment_low(9)) or
			(g_segment_low(9) = 'LK' and segment9 like g_segment_high(9)) or (g_segment_low(9) is not null and g_segment_high(9) is not null and g_segment_low(9) <> 'LK' and segment9 between g_segment_low(9) and g_segment_high(9)) )
		and ( (segment10 is null) or (g_segment_low(10) is null and g_segment_high(10) is null) or (g_segment_low(10) is null and segment10 <= g_segment_high(10)) or (g_segment_high(10) is null and segment10 >= g_segment_low(10)) or
			(g_segment_low(10) = 'LK' and segment10 like g_segment_high(10)) or (g_segment_low(10) is not null and g_segment_high(10) is not null and g_segment_low(10) <> 'LK' and segment10 between g_segment_low(10) and g_segment_high(10)) )
		and ( (segment11 is null) or (g_segment_low(11) is null and g_segment_high(11) is null) or (g_segment_low(11) is null and segment11 <= g_segment_high(11)) or (g_segment_high(11) is null and segment11 >= g_segment_low(11)) or
			(g_segment_low(11) = 'LK' and segment11 like g_segment_high(11)) or (g_segment_low(11) is not null and g_segment_high(11) is not null and g_segment_low(11) <> 'LK' and segment11 between g_segment_low(11) and g_segment_high(11)) )
		and ( (segment12 is null) or (g_segment_low(12) is null and g_segment_high(12) is null) or (g_segment_low(12) is null and segment12 <= g_segment_high(12)) or (g_segment_high(12) is null and segment12 >= g_segment_low(12)) or
			(g_segment_low(12) = 'LK' and segment12 like g_segment_high(12)) or (g_segment_low(12) is not null and g_segment_high(12) is not null and g_segment_low(12) <> 'LK' and segment12 between g_segment_low(12) and g_segment_high(12)) )
		and ( (segment13 is null) or (g_segment_low(13) is null and g_segment_high(13) is null) or (g_segment_low(13) is null and segment13 <= g_segment_high(13)) or (g_segment_high(13) is null and segment13 >= g_segment_low(13)) or
			(g_segment_low(13) = 'LK' and segment13 like g_segment_high(13)) or (g_segment_low(13) is not null and g_segment_high(13) is not null and g_segment_low(13) <> 'LK' and segment13 between g_segment_low(13) and g_segment_high(13)) )
		and ( (segment14 is null) or (g_segment_low(14) is null and g_segment_high(14) is null) or (g_segment_low(14) is null and segment14 <= g_segment_high(14)) or (g_segment_high(14) is null and segment14 >= g_segment_low(14)) or
			(g_segment_low(14) = 'LK' and segment14 like g_segment_high(14)) or (g_segment_low(14) is not null and g_segment_high(14) is not null and g_segment_low(14) <> 'LK' and segment14 between g_segment_low(14) and g_segment_high(14)) )
		and ( (segment15 is null) or (g_segment_low(15) is null and g_segment_high(15) is null) or (g_segment_low(15) is null and segment15 <= g_segment_high(15)) or (g_segment_high(15) is null and segment15 >= g_segment_low(15)) or
			(g_segment_low(15) = 'LK' and segment15 like g_segment_high(15)) or (g_segment_low(15) is not null and g_segment_high(15) is not null and g_segment_low(15) <> 'LK' and segment15 between g_segment_low(15) and g_segment_high(15)) )
		and ( (segment16 is null) or (g_segment_low(16) is null and g_segment_high(16) is null) or (g_segment_low(16) is null and segment16 <= g_segment_high(16)) or (g_segment_high(16) is null and segment16 >= g_segment_low(16)) or
			(g_segment_low(16) = 'LK' and segment16 like g_segment_high(16)) or (g_segment_low(16) is not null and g_segment_high(16) is not null and g_segment_low(16) <> 'LK' and segment16 between g_segment_low(16) and g_segment_high(16)) )
		and ( (segment17 is null) or (g_segment_low(17) is null and g_segment_high(17) is null) or (g_segment_low(17) is null and segment17 <= g_segment_high(17)) or (g_segment_high(17) is null and segment17 >= g_segment_low(17)) or
			(g_segment_low(17) = 'LK' and segment17 like g_segment_high(17)) or (g_segment_low(17) is not null and g_segment_high(17) is not null and g_segment_low(17) <> 'LK' and segment17 between g_segment_low(17) and g_segment_high(17)) )
		and ( (segment18 is null) or (g_segment_low(18) is null and g_segment_high(18) is null) or (g_segment_low(18) is null and segment18 <= g_segment_high(18)) or (g_segment_high(18) is null and segment18 >= g_segment_low(18)) or
			(g_segment_low(18) = 'LK' and segment18 like g_segment_high(18)) or (g_segment_low(18) is not null and g_segment_high(18) is not null and g_segment_low(18) <> 'LK' and segment18 between g_segment_low(18) and g_segment_high(18)) )
		and ( (segment19 is null) or (g_segment_low(19) is null and g_segment_high(19) is null) or (g_segment_low(19) is null and segment19 <= g_segment_high(19)) or (g_segment_high(19) is null and segment19 >= g_segment_low(19)) or
			(g_segment_low(19) = 'LK' and segment19 like g_segment_high(19)) or (g_segment_low(19) is not null and g_segment_high(19) is not null and g_segment_low(19) <> 'LK' and segment19 between g_segment_low(19) and g_segment_high(19)) )
		and ( (segment20 is null) or (g_segment_low(20) is null and g_segment_high(20) is null) or (g_segment_low(20) is null and segment20 <= g_segment_high(20)) or (g_segment_high(20) is null and segment20 >= g_segment_low(20)) or
			(g_segment_low(20) = 'LK' and segment20 like g_segment_high(20)) or (g_segment_low(20) is not null and g_segment_high(20) is not null and g_segment_low(20) <> 'LK' and segment20 between g_segment_low(20) and g_segment_high(20)) )
		and ( (segment21 is null) or (g_segment_low(21) is null and g_segment_high(21) is null) or (g_segment_low(21) is null and segment21 <= g_segment_high(21)) or (g_segment_high(21) is null and segment21 >= g_segment_low(21)) or
			(g_segment_low(21) = 'LK' and segment21 like g_segment_high(21)) or (g_segment_low(21) is not null and g_segment_high(21) is not null and g_segment_low(21) <> 'LK' and segment21 between g_segment_low(21) and g_segment_high(21)) )
		and ( (segment22 is null) or (g_segment_low(22) is null and g_segment_high(22) is null) or (g_segment_low(22) is null and segment22 <= g_segment_high(22)) or (g_segment_high(22) is null and segment22 >= g_segment_low(22)) or
			(g_segment_low(22) = 'LK' and segment22 like g_segment_high(22)) or (g_segment_low(22) is not null and g_segment_high(22) is not null and g_segment_low(22) <> 'LK' and segment22 between g_segment_low(22) and g_segment_high(22)) )
		and ( (segment23 is null) or (g_segment_low(23) is null and g_segment_high(23) is null) or (g_segment_low(23) is null and segment23 <= g_segment_high(23)) or (g_segment_high(23) is null and segment23 >= g_segment_low(23)) or
			(g_segment_low(23) = 'LK' and segment23 like g_segment_high(23)) or (g_segment_low(23) is not null and g_segment_high(23) is not null and g_segment_low(23) <> 'LK' and segment23 between g_segment_low(23) and g_segment_high(23)) )
		and ( (segment24 is null) or (g_segment_low(24) is null and g_segment_high(24) is null) or (g_segment_low(24) is null and segment24 <= g_segment_high(24)) or (g_segment_high(24) is null and segment24 >= g_segment_low(24)) or
			(g_segment_low(24) = 'LK' and segment24 like g_segment_high(24)) or (g_segment_low(24) is not null and g_segment_high(24) is not null and g_segment_low(24) <> 'LK' and segment24 between g_segment_low(24) and g_segment_high(24)) )
		and ( (segment25 is null) or (g_segment_low(25) is null and g_segment_high(25) is null) or (g_segment_low(25) is null and segment25 <= g_segment_high(25)) or (g_segment_high(25) is null and segment25 >= g_segment_low(25)) or
			(g_segment_low(25) = 'LK' and segment25 like g_segment_high(25)) or (g_segment_low(25) is not null and g_segment_high(25) is not null and g_segment_low(25) <> 'LK' and segment25 between g_segment_low(25) and g_segment_high(25)) )
		and ( (segment26 is null) or (g_segment_low(26) is null and g_segment_high(26) is null) or (g_segment_low(26) is null and segment26 <= g_segment_high(26)) or (g_segment_high(26) is null and segment26 >= g_segment_low(26)) or
			(g_segment_low(26) = 'LK' and segment26 like g_segment_high(26)) or (g_segment_low(26) is not null and g_segment_high(26) is not null and g_segment_low(26) <> 'LK' and segment26 between g_segment_low(26) and g_segment_high(26)) )
		and ( (segment27 is null) or (g_segment_low(27) is null and g_segment_high(27) is null) or (g_segment_low(27) is null and segment27 <= g_segment_high(27)) or (g_segment_high(27) is null and segment27 >= g_segment_low(27)) or
			(g_segment_low(27) = 'LK' and segment27 like g_segment_high(27)) or (g_segment_low(27) is not null and g_segment_high(27) is not null and g_segment_low(27) <> 'LK' and segment27 between g_segment_low(27) and g_segment_high(27)) )
		and ( (segment28 is null) or (g_segment_low(28) is null and g_segment_high(28) is null) or (g_segment_low(28) is null and segment28 <= g_segment_high(28)) or (g_segment_high(28) is null and segment28 >= g_segment_low(28)) or
			(g_segment_low(28) = 'LK' and segment28 like g_segment_high(28)) or (g_segment_low(28) is not null and g_segment_high(28) is not null and g_segment_low(28) <> 'LK' and segment28 between g_segment_low(28) and g_segment_high(28)) )
		and ( (segment29 is null) or (g_segment_low(29) is null and g_segment_high(29) is null) or (g_segment_low(29) is null and segment29 <= g_segment_high(29)) or (g_segment_high(29) is null and segment29 >= g_segment_low(29)) or
			(g_segment_low(29) = 'LK' and segment29 like g_segment_high(29)) or (g_segment_low(29) is not null and g_segment_high(29) is not null and g_segment_low(29) <> 'LK' and segment29 between g_segment_low(29) and g_segment_high(29)) )
		and ( (segment30 is null) or (g_segment_low(30) is null and g_segment_high(30) is null) or (g_segment_low(30) is null and segment30 <= g_segment_high(30)) or (g_segment_high(30) is null and segment30 >= g_segment_low(30)) or
			(g_segment_low(30) = 'LK' and segment30 like g_segment_high(30)) or (g_segment_low(30) is not null and g_segment_high(30) is not null and g_segment_low(30) <> 'LK' and segment30 between g_segment_low(30) and g_segment_high(30)) ));