473,569 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Insert into and FETCH FIRST ROW ONLY

I am trying to insert into a temporary table but only the first n
number of rows. I thought I could use the combination of insert into
and fect first row command ,but it won't work. Does anyone know why?

Any other suggestions other than writing a loop? This is in a db2 sql
stored procedure that is called from another db2 sql stored proc.

Dec 14 '06 #1
15 10825
"dataguy" <ba*********@pr ogressive.comwr ote in message
news:11******** **************@ j72g2000cwa.goo glegroups.com.. .
>I am trying to insert into a temporary table but only the first n
number of rows. I thought I could use the combination of insert into
and fect first row command ,but it won't work. Does anyone know why?

Any other suggestions other than writing a loop? This is in a db2 sql
stored procedure that is called from another db2 sql stored proc.
If you post the SQL, then maybe someone will be able to help you.
Dec 15 '06 #2
dataguy wrote:
I am trying to insert into a temporary table but only the first n
number of rows. I thought I could use the combination of insert into
and fect first row command ,but it won't work. Does anyone know why?

Any other suggestions other than writing a loop? This is in a db2 sql
stored procedure that is called from another db2 sql stored proc.
Is this what you are looking for?
INSERT INTO SESSION.TEMP SELECT * FROM T FETCH FIRST 10 ROWS ONLY

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Dec 15 '06 #3
When we tried to issue the statement similar to what you have below, we
kept getting an error complaining about the fetch. When we removed the
"fetch first xx rows only" and tried it, no problem.. I can post the
sql if you want it.
Serge Rielau wrote:
dataguy wrote:
I am trying to insert into a temporary table but only the first n
number of rows. I thought I could use the combination of insert into
and fect first row command ,but it won't work. Does anyone know why?

Any other suggestions other than writing a loop? This is in a db2 sql
stored procedure that is called from another db2 sql stored proc.
Is this what you are looking for?
INSERT INTO SESSION.TEMP SELECT * FROM T FETCH FIRST 10 ROWS ONLY

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Dec 15 '06 #4
Here is the SQL in Question:

Note.. We tried putting an open and closed paran around the select
statements and it didn't help.
INSERT
INTO SESSION.NAM_TBL
SELECT PRNW.POL_ID_NBR AS PolicyNumber,
PRNW.RENW_SFX_N BR AS PolicySuffix,
PDTL.POL_STRT_D T AS PolicyStartDate ,
PDTL.POL_END_DT AS PolicyEndDate,
PDTL.POL_SRCE_C D AS PolicySourcecd,
PDTL.POL_ST_CD AS PolicyStateCd,
PDTL.PROD_CTGRY _CD AS ProductCategory Cd,
ADRS.PRTY_STR_N AM AS StreetName,
ADRS.PRTY_CITY_ NAM AS CityName,
ADRS.PRTY_ST_CD AS StateCd,
ADRS.PRTY_ZIP_C D AS ZipCd,
ADRS.PRTY_ZIP_C D_EXTN AS ZipCdExtn,
PRTY.PRTY_TYP_C D AS PartyTypeCd,
PRTY.PRTY_BRTH_ DT AS PartyDOB,
PRTY.PRTY_BSNS_ IND AS PartyBusinessIn d,
PRTY.PRTY_NAM AS PartyName

-- RP910-PRTY-LST-NAM
-- RP910-PRTY-FRST-NAM
-- RP910-PRTY-NAM-INIT
-- RP910-PRTY-NAM-SFX

FROM PMTPSM_APH_PRTY PRTY
INNER JOIN PMTPSM_APH_POL_ RNW PRNW
ON PRTY.POL_RENEW_ KEY = PRNW.POL_RENEW_ KEY
AND PRTY.PART_KEY = PRNW.PART_KEY
INNER JOIN PMTPSM_APH_POL_ DTL PDTL
ON PRNW.POL_RENEW_ KEY = PDTL.POL_RENEW_ KEY
AND PRNW.PART_KEY = PDTL.PART_KEY
LEFT OUTER JOIN PMTPSM_APH_ADRS ADRS
ON PRNW.POL_RENEW_ KEY = ADRS.POL_RENEW_ KEY
AND PRNW.PART_KEY = ADRS.PART_KEY

--
-- NAME PREDICATES FOR APH_PRTY
--

WHERE PRTY.PRTY_LST_N AM LIKE W_SRCH_LAST_NAM
AND PRTY.PRTY_FRST_ NAM LIKE W_SRCH_FRST_NAM
AND (
(PRTY.PROC_EFF_ TS <= CURRENT_TIMESTA MP
AND
PRTY.PROC_EXPR_ TS CURRENT_TIMESTA MP
AND
PRTY.ITR_EFF_DT <= W_REF_DATE
)
OR
(PRTY.PROC_EXPR _TS <= CURRENT_TIMESTA MP
AND
PRTY.ITR_EFF_DT <= W_REF_DATE
AND
PRTY.ITR_EXPR_D T W_REF_DATE
)
)

--
-- APH_POL_DTL PREDICATES
--

AND (
(PDTL.PROC_EFF_ TS <= CURRENT_TIMESTA MP
AND
CASE WHEN PDTL.PROC_EXPR_ DT = W_MAX_DATE
THEN TIMESTAMP (PDTL.POL_END_D T, PDTL.PROC_EXPR_ TM)
ELSE PDTL.PROC_EXPR_ TS
END
CURRENT_TIMESTA MP
AND
PDTL.ITR_EFF_DT <= W_REF_DATE
)
OR
(CASE WHEN PDTL.PROC_EXPR_ DT = W_MAX_DATE
THEN TIMESTAMP (PDTL.POL_END_D T, PDTL.PROC_EXPR_ TM)
ELSE PDTL.PROC_EXPR_ TS
END
<= CURRENT_TIMESTA MP
AND
PDTL.ITR_EFF_DT <= W_REF_DATE
AND
CASE WHEN PDTL.ITR_EXPR_D T = W_MAX_DATE
THEN PDTL.POL_END_DT
ELSE PDTL.ITR_EXPR_D T
END
W_REF_DATE
)
)

--
-- SUB SELECT TO RETRIEVE ONLY ONE APH_POL_DTL ROW
--

AND PDTL.PROC_EFF_T S =
(SELECT MAX(PDTL2.PROC_ EFF_TS)
FROM PMTPSM_APH_POL_ DTL PDTL2
WHERE PDTL2.POL_RENEW _KEY = PDTL.POL_RENEW_ KEY
AND PDTL2.PART_KEY = PDTL.PART_KEY
AND (
(PDTL2.PROC_EFF _TS <= CURRENT_TIMESTA MP
AND
PDTL2.PROC_EXPR _TS CURRENT_TIMESTA MP
AND
PDTL2.ITR_EFF_D T <= W_REF_DATE
)
OR
(PDTL2.PROC_EXP R_TS <= CURRENT_TIMESTA MP
AND
PDTL2.ITR_EFF_D T <= W_REF_DATE
AND
PDTL2.ITR_EXPR_ DT W_REF_DATE
)
)
)

--
-- APH_ADRS PREDICATES
--

AND (
(ADRS.PROC_EFF_ TS <= CURRENT_TIMESTA MP
AND
ADRS.PROC_EXPR_ TS CURRENT_TIMESTA MP
AND
ADRS.ITR_EFF_DT <= W_REF_DATE
)
OR
(ADRS.PROC_EXPR _TS <= CURRENT_TIMESTA MP
AND
ADRS.ITR_EFF_DT <= W_REF_DATE
AND
ADRS.ITR_EXPR_D T W_REF_DATE
)
OR
(ADRS.PROC_EFF_ DT IS NULL
AND
ADRS.PROC_EFF_T M IS NULL
AND
ADRS.PROC_EXPR_ DT IS NULL
AND
ADRS.PROC_EXPR_ TM IS NULL
AND
ADRS.ITR_EFF_DT IS NULL
AND
ADRS.ITR_EXPR_D T IS NULL
)
)

--
-- SUB SELECT TO RETRIEVE ONLY ONE APH_ADRS ROW
--

AND ADRS.PROC_EFF_T S =
(SELECT MAX(ADRS2.PROC_ EFF_TS)
FROM PMTPSM_APH_ADRS ADRS2
WHERE ADRS2.POL_RENEW _KEY = ADRS.POL_RENEW_ KEY
AND ADRS2.PART_KEY = ADRS.PART_KEY
AND (
(ADRS2.PROC_EFF _TS <= CURRENT_TIMESTA MP
AND
ADRS2.PROC_EXPR _TS CURRENT_TIMESTA MP
AND
ADRS2.ITR_EFF_D T <= W_REF_DATE
)
OR
(ADRS2.PROC_EXP R_TS <= CURRENT_TIMESTA MP
AND
ADRS2.ITR_EFF_D T <= W_REF_DATE
AND
ADRS2.ITR_EXPR_ DT W_REF_DATE
)
OR
(ADRS2.PROC_EFF _DT IS NULL
AND
ADRS2.PROC_EFF_ TM IS NULL
AND
ADRS2.PROC_EXPR _DT IS NULL
AND
ADRS2.PROC_EXPR _TM IS NULL
AND
ADRS2.ITR_EFF_D T IS NULL
AND
ADRS2.ITR_EXPR_ DT IS NULL
)
)
)
FETCH FIRST 70 ROWS ONLY
WITH UR;

Mark A wrote:
"dataguy" <ba*********@pr ogressive.comwr ote in message
news:11******** **************@ j72g2000cwa.goo glegroups.com.. .
I am trying to insert into a temporary table but only the first n
number of rows. I thought I could use the combination of insert into
and fect first row command ,but it won't work. Does anyone know why?

Any other suggestions other than writing a loop? This is in a db2 sql
stored procedure that is called from another db2 sql stored proc.

If you post the SQL, then maybe someone will be able to help you.
Dec 15 '06 #5

dataguy wrote:
When we tried to issue the statement similar to what you have below, we
kept getting an error complaining about the fetch. When we removed the
"fetch first xx rows only" and tried it, no problem.. I can post the
sql if you want it.
Serge Rielau wrote:
dataguy wrote:
I am trying to insert into a temporary table but only the first n
number of rows. I thought I could use the combination of insert into
and fect first row command ,but it won't work. Does anyone know why?
>
Any other suggestions other than writing a loop? This is in a db2 sql
stored procedure that is called from another db2 sql stored proc.
>
Is this what you are looking for?
INSERT INTO SESSION.TEMP SELECT * FROM T FETCH FIRST 10 ROWS ONLY

Cheers
Serge

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Please post the SQL. It can be very helpful.

B.

Dec 15 '06 #6

dataguy wrote:
Here is the SQL in Question:

Note.. We tried putting an open and closed paran around the select
statements and it didn't help.
INSERT
INTO SESSION.NAM_TBL
SELECT PRNW.POL_ID_NBR AS PolicyNumber,
PRNW.RENW_SFX_N BR AS PolicySuffix,
PDTL.POL_STRT_D T AS PolicyStartDate ,
PDTL.POL_END_DT AS PolicyEndDate,
PDTL.POL_SRCE_C D AS PolicySourcecd,
PDTL.POL_ST_CD AS PolicyStateCd,
PDTL.PROD_CTGRY _CD AS ProductCategory Cd,
ADRS.PRTY_STR_N AM AS StreetName,
ADRS.PRTY_CITY_ NAM AS CityName,
ADRS.PRTY_ST_CD AS StateCd,
ADRS.PRTY_ZIP_C D AS ZipCd,
ADRS.PRTY_ZIP_C D_EXTN AS ZipCdExtn,
PRTY.PRTY_TYP_C D AS PartyTypeCd,
PRTY.PRTY_BRTH_ DT AS PartyDOB,
PRTY.PRTY_BSNS_ IND AS PartyBusinessIn d,
PRTY.PRTY_NAM AS PartyName

-- RP910-PRTY-LST-NAM
-- RP910-PRTY-FRST-NAM
-- RP910-PRTY-NAM-INIT
-- RP910-PRTY-NAM-SFX

FROM PMTPSM_APH_PRTY PRTY
INNER JOIN PMTPSM_APH_POL_ RNW PRNW
ON PRTY.POL_RENEW_ KEY = PRNW.POL_RENEW_ KEY
AND PRTY.PART_KEY = PRNW.PART_KEY
INNER JOIN PMTPSM_APH_POL_ DTL PDTL
ON PRNW.POL_RENEW_ KEY = PDTL.POL_RENEW_ KEY
AND PRNW.PART_KEY = PDTL.PART_KEY
LEFT OUTER JOIN PMTPSM_APH_ADRS ADRS
ON PRNW.POL_RENEW_ KEY = ADRS.POL_RENEW_ KEY
AND PRNW.PART_KEY = ADRS.PART_KEY

--
-- NAME PREDICATES FOR APH_PRTY
--

WHERE PRTY.PRTY_LST_N AM LIKE W_SRCH_LAST_NAM
AND PRTY.PRTY_FRST_ NAM LIKE W_SRCH_FRST_NAM
AND (
(PRTY.PROC_EFF_ TS <= CURRENT_TIMESTA MP
AND
PRTY.PROC_EXPR_ TS CURRENT_TIMESTA MP
AND
PRTY.ITR_EFF_DT <= W_REF_DATE
)
OR
(PRTY.PROC_EXPR _TS <= CURRENT_TIMESTA MP
AND
PRTY.ITR_EFF_DT <= W_REF_DATE
AND
PRTY.ITR_EXPR_D T W_REF_DATE
)
)

--
-- APH_POL_DTL PREDICATES
--

AND (
(PDTL.PROC_EFF_ TS <= CURRENT_TIMESTA MP
AND
CASE WHEN PDTL.PROC_EXPR_ DT = W_MAX_DATE
THEN TIMESTAMP (PDTL.POL_END_D T, PDTL.PROC_EXPR_ TM)
ELSE PDTL.PROC_EXPR_ TS
END
CURRENT_TIMESTA MP
AND
PDTL.ITR_EFF_DT <= W_REF_DATE
)
OR
(CASE WHEN PDTL.PROC_EXPR_ DT = W_MAX_DATE
THEN TIMESTAMP (PDTL.POL_END_D T, PDTL.PROC_EXPR_ TM)
ELSE PDTL.PROC_EXPR_ TS
END
<= CURRENT_TIMESTA MP
AND
PDTL.ITR_EFF_DT <= W_REF_DATE
AND
CASE WHEN PDTL.ITR_EXPR_D T = W_MAX_DATE
THEN PDTL.POL_END_DT
ELSE PDTL.ITR_EXPR_D T
END
W_REF_DATE
)
)

--
-- SUB SELECT TO RETRIEVE ONLY ONE APH_POL_DTL ROW
--

AND PDTL.PROC_EFF_T S =
(SELECT MAX(PDTL2.PROC_ EFF_TS)
FROM PMTPSM_APH_POL_ DTL PDTL2
WHERE PDTL2.POL_RENEW _KEY = PDTL.POL_RENEW_ KEY
AND PDTL2.PART_KEY = PDTL.PART_KEY
AND (
(PDTL2.PROC_EFF _TS <= CURRENT_TIMESTA MP
AND
PDTL2.PROC_EXPR _TS CURRENT_TIMESTA MP
AND
PDTL2.ITR_EFF_D T <= W_REF_DATE
)
OR
(PDTL2.PROC_EXP R_TS <= CURRENT_TIMESTA MP
AND
PDTL2.ITR_EFF_D T <= W_REF_DATE
AND
PDTL2.ITR_EXPR_ DT W_REF_DATE
)
)
)

--
-- APH_ADRS PREDICATES
--

AND (
(ADRS.PROC_EFF_ TS <= CURRENT_TIMESTA MP
AND
ADRS.PROC_EXPR_ TS CURRENT_TIMESTA MP
AND
ADRS.ITR_EFF_DT <= W_REF_DATE
)
OR
(ADRS.PROC_EXPR _TS <= CURRENT_TIMESTA MP
AND
ADRS.ITR_EFF_DT <= W_REF_DATE
AND
ADRS.ITR_EXPR_D T W_REF_DATE
)
OR
(ADRS.PROC_EFF_ DT IS NULL
AND
ADRS.PROC_EFF_T M IS NULL
AND
ADRS.PROC_EXPR_ DT IS NULL
AND
ADRS.PROC_EXPR_ TM IS NULL
AND
ADRS.ITR_EFF_DT IS NULL
AND
ADRS.ITR_EXPR_D T IS NULL
)
)

--
-- SUB SELECT TO RETRIEVE ONLY ONE APH_ADRS ROW
--

AND ADRS.PROC_EFF_T S =
(SELECT MAX(ADRS2.PROC_ EFF_TS)
FROM PMTPSM_APH_ADRS ADRS2
WHERE ADRS2.POL_RENEW _KEY = ADRS.POL_RENEW_ KEY
AND ADRS2.PART_KEY = ADRS.PART_KEY
AND (
(ADRS2.PROC_EFF _TS <= CURRENT_TIMESTA MP
AND
ADRS2.PROC_EXPR _TS CURRENT_TIMESTA MP
AND
ADRS2.ITR_EFF_D T <= W_REF_DATE
)
OR
(ADRS2.PROC_EXP R_TS <= CURRENT_TIMESTA MP
AND
ADRS2.ITR_EFF_D T <= W_REF_DATE
AND
ADRS2.ITR_EXPR_ DT W_REF_DATE
)
OR
(ADRS2.PROC_EFF _DT IS NULL
AND
ADRS2.PROC_EFF_ TM IS NULL
AND
ADRS2.PROC_EXPR _DT IS NULL
AND
ADRS2.PROC_EXPR _TM IS NULL
AND
ADRS2.ITR_EFF_D T IS NULL
AND
ADRS2.ITR_EXPR_ DT IS NULL
)
)
)
FETCH FIRST 70 ROWS ONLY
WITH UR;

Mark A wrote:
"dataguy" <ba*********@pr ogressive.comwr ote in message
news:11******** **************@ j72g2000cwa.goo glegroups.com.. .
>I am trying to insert into a temporary table but only the first n
number of rows. I thought I could use the combination of insert into
and fect first row command ,but it won't work. Does anyone know why?
>
Any other suggestions other than writing a loop? This is in a db2 sql
stored procedure that is called from another db2 sql stored proc.
If you post the SQL, then maybe someone will be able to help you.
Two questions:

1) If you remove the INSERT part of the statement, does the SELECT
statement execute without error?

2) What is the error returned?

B.

Dec 15 '06 #7
... which platform?

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Dec 15 '06 #8
Db2 is OS/390, but we are doing it from stored procedure builder on the
client.
Serge Rielau wrote:
.. which platform?

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

WAIUG Conference
http://www.iiug.org/waiug/present/Fo...Forum2006.html
Dec 15 '06 #9
We the select statement only and it works. Even if it was the select
statement, why would it work ok when I remove the Fetch statement?

As far as the error message, the person I'm working with has re-written
it to use a loop. It will take a bit of time to re-write it without.
I'll see if he can.
Brian Tkatch wrote:
dataguy wrote:
Here is the SQL in Question:

Note.. We tried putting an open and closed paran around the select
statements and it didn't help.
INSERT
INTO SESSION.NAM_TBL
SELECT PRNW.POL_ID_NBR AS PolicyNumber,
PRNW.RENW_SFX_N BR AS PolicySuffix,
PDTL.POL_STRT_D T AS PolicyStartDate ,
PDTL.POL_END_DT AS PolicyEndDate,
PDTL.POL_SRCE_C D AS PolicySourcecd,
PDTL.POL_ST_CD AS PolicyStateCd,
PDTL.PROD_CTGRY _CD AS ProductCategory Cd,
ADRS.PRTY_STR_N AM AS StreetName,
ADRS.PRTY_CITY_ NAM AS CityName,
ADRS.PRTY_ST_CD AS StateCd,
ADRS.PRTY_ZIP_C D AS ZipCd,
ADRS.PRTY_ZIP_C D_EXTN AS ZipCdExtn,
PRTY.PRTY_TYP_C D AS PartyTypeCd,
PRTY.PRTY_BRTH_ DT AS PartyDOB,
PRTY.PRTY_BSNS_ IND AS PartyBusinessIn d,
PRTY.PRTY_NAM AS PartyName

-- RP910-PRTY-LST-NAM
-- RP910-PRTY-FRST-NAM
-- RP910-PRTY-NAM-INIT
-- RP910-PRTY-NAM-SFX

FROM PMTPSM_APH_PRTY PRTY
INNER JOIN PMTPSM_APH_POL_ RNW PRNW
ON PRTY.POL_RENEW_ KEY = PRNW.POL_RENEW_ KEY
AND PRTY.PART_KEY = PRNW.PART_KEY
INNER JOIN PMTPSM_APH_POL_ DTL PDTL
ON PRNW.POL_RENEW_ KEY = PDTL.POL_RENEW_ KEY
AND PRNW.PART_KEY = PDTL.PART_KEY
LEFT OUTER JOIN PMTPSM_APH_ADRS ADRS
ON PRNW.POL_RENEW_ KEY = ADRS.POL_RENEW_ KEY
AND PRNW.PART_KEY = ADRS.PART_KEY

--
-- NAME PREDICATES FOR APH_PRTY
--

WHERE PRTY.PRTY_LST_N AM LIKE W_SRCH_LAST_NAM
AND PRTY.PRTY_FRST_ NAM LIKE W_SRCH_FRST_NAM
AND (
(PRTY.PROC_EFF_ TS <= CURRENT_TIMESTA MP
AND
PRTY.PROC_EXPR_ TS CURRENT_TIMESTA MP
AND
PRTY.ITR_EFF_DT <= W_REF_DATE
)
OR
(PRTY.PROC_EXPR _TS <= CURRENT_TIMESTA MP
AND
PRTY.ITR_EFF_DT <= W_REF_DATE
AND
PRTY.ITR_EXPR_D T W_REF_DATE
)
)

--
-- APH_POL_DTL PREDICATES
--

AND (
(PDTL.PROC_EFF_ TS <= CURRENT_TIMESTA MP
AND
CASE WHEN PDTL.PROC_EXPR_ DT = W_MAX_DATE
THEN TIMESTAMP (PDTL.POL_END_D T, PDTL.PROC_EXPR_ TM)
ELSE PDTL.PROC_EXPR_ TS
END
CURRENT_TIMESTA MP
AND
PDTL.ITR_EFF_DT <= W_REF_DATE
)
OR
(CASE WHEN PDTL.PROC_EXPR_ DT = W_MAX_DATE
THEN TIMESTAMP (PDTL.POL_END_D T, PDTL.PROC_EXPR_ TM)
ELSE PDTL.PROC_EXPR_ TS
END
<= CURRENT_TIMESTA MP
AND
PDTL.ITR_EFF_DT <= W_REF_DATE
AND
CASE WHEN PDTL.ITR_EXPR_D T = W_MAX_DATE
THEN PDTL.POL_END_DT
ELSE PDTL.ITR_EXPR_D T
END
W_REF_DATE
)
)

--
-- SUB SELECT TO RETRIEVE ONLY ONE APH_POL_DTL ROW
--

AND PDTL.PROC_EFF_T S =
(SELECT MAX(PDTL2.PROC_ EFF_TS)
FROM PMTPSM_APH_POL_ DTL PDTL2
WHERE PDTL2.POL_RENEW _KEY = PDTL.POL_RENEW_ KEY
AND PDTL2.PART_KEY = PDTL.PART_KEY
AND (
(PDTL2.PROC_EFF _TS <= CURRENT_TIMESTA MP
AND
PDTL2.PROC_EXPR _TS CURRENT_TIMESTA MP
AND
PDTL2.ITR_EFF_D T <= W_REF_DATE
)
OR
(PDTL2.PROC_EXP R_TS <= CURRENT_TIMESTA MP
AND
PDTL2.ITR_EFF_D T <= W_REF_DATE
AND
PDTL2.ITR_EXPR_ DT W_REF_DATE
)
)
)

--
-- APH_ADRS PREDICATES
--

AND (
(ADRS.PROC_EFF_ TS <= CURRENT_TIMESTA MP
AND
ADRS.PROC_EXPR_ TS CURRENT_TIMESTA MP
AND
ADRS.ITR_EFF_DT <= W_REF_DATE
)
OR
(ADRS.PROC_EXPR _TS <= CURRENT_TIMESTA MP
AND
ADRS.ITR_EFF_DT <= W_REF_DATE
AND
ADRS.ITR_EXPR_D T W_REF_DATE
)
OR
(ADRS.PROC_EFF_ DT IS NULL
AND
ADRS.PROC_EFF_T M IS NULL
AND
ADRS.PROC_EXPR_ DT IS NULL
AND
ADRS.PROC_EXPR_ TM IS NULL
AND
ADRS.ITR_EFF_DT IS NULL
AND
ADRS.ITR_EXPR_D T IS NULL
)
)

--
-- SUB SELECT TO RETRIEVE ONLY ONE APH_ADRS ROW
--

AND ADRS.PROC_EFF_T S =
(SELECT MAX(ADRS2.PROC_ EFF_TS)
FROM PMTPSM_APH_ADRS ADRS2
WHERE ADRS2.POL_RENEW _KEY = ADRS.POL_RENEW_ KEY
AND ADRS2.PART_KEY = ADRS.PART_KEY
AND (
(ADRS2.PROC_EFF _TS <= CURRENT_TIMESTA MP
AND
ADRS2.PROC_EXPR _TS CURRENT_TIMESTA MP
AND
ADRS2.ITR_EFF_D T <= W_REF_DATE
)
OR
(ADRS2.PROC_EXP R_TS <= CURRENT_TIMESTA MP
AND
ADRS2.ITR_EFF_D T <= W_REF_DATE
AND
ADRS2.ITR_EXPR_ DT W_REF_DATE
)
OR
(ADRS2.PROC_EFF _DT IS NULL
AND
ADRS2.PROC_EFF_ TM IS NULL
AND
ADRS2.PROC_EXPR _DT IS NULL
AND
ADRS2.PROC_EXPR _TM IS NULL
AND
ADRS2.ITR_EFF_D T IS NULL
AND
ADRS2.ITR_EXPR_ DT IS NULL
)
)
)
FETCH FIRST 70 ROWS ONLY
WITH UR;

Mark A wrote:
"dataguy" <ba*********@pr ogressive.comwr ote in message
news:11******** **************@ j72g2000cwa.goo glegroups.com.. .
I am trying to insert into a temporary table but only the first n
number of rows. I thought I could use the combination of insert into
and fect first row command ,but it won't work. Does anyone know why?

Any other suggestions other than writing a loop? This is in a db2 sql
stored procedure that is called from another db2 sql stored proc.
>
If you post the SQL, then maybe someone will be able to help you.

Two questions:

1) If you remove the INSERT part of the statement, does the SELECT
statement execute without error?

2) What is the error returned?

B.
Dec 15 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
21093
by: Evan Smith | last post by:
During a routine performance check using an event monitor, I discovered a class of query whose performance has me baffled. The monitor captured: SELECT * FROM EWM_CASE fetch first 1 rows only It took 14 seconds of CPU time to execute. After looking up the documentation on the FETCH FIRST notation I find "Limiting the result table to...
2
3884
by: deebeetwo | last post by:
I am trying to select only a certain number of records from a table. It is easy enough with "fetch first" syntax. What complicates this a bit is the fact that I need to retrieve the number of rows from another table. So: begin atomic declare num_records int default 0; set num_records = (select number_of_rows from master_table); select *...
13
6751
by: RR | last post by:
Hi, It appears that DB2 has an arbitrary restriction on the use of "fetch first N rows". I want to insert into a table from a large table query, but only insert the first N rows: insert into target (select colA,colB from source where conditions fetch first 1000 rows only);
5
9889
by: Bernd Hohmann | last post by:
Is there any way to create a dynamic row limit like "fetch first ? rows only" using the JDBC driver and a PreparedStatement? Bernd -- "Ja, alles meine Herren" sprach Fürst Lichnowsky. "Ooch det roochen?" "Ja, auch das Rauchen." "Ooch im Tiergarten?" "Ja, auch im Tiergarten darf geraucht werden, meine Herren." Und so endeten die...
9
11069
by: Acupuncture | last post by:
Hi, I am developing a JDBC application and I encountered this problem (DB2 for ISeries). I want to do a select for update and also use the fetch first rows clause. This is my sql statement: SELECT UsrNbr, UsrPwd, UsrPwdChgD, UsrEmail, UsrChgUsrI, UsrChgDte FROM USERS WHERE UsrNbr = ? FETCH FIRST 1 ROWS ONLY FOR UPDATE This runs fine...
14
16721
by: sangram.0149 | last post by:
hi, can someone plz help me on this one i need to fetch the first record from every group of records with the same emp id. i cannot use group by because i want to fetch all the fields corresponding to a particular empid. plz suggest a solution for this one regards, Sangram
3
40468
by: nymano | last post by:
Hi. Just a brief question: Are "FETCH FIRST ROW ONLY" and "FETCH FIRST x ROWS ONLY" DB2 specific or SQL92? thanks for any help, nymano.
0
7695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.