If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Problem in fetch first n rows in DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-22-09, 05:19
vivek.vivek vivek.vivek is offline
Registered User
 
Join Date: Jan 2009
Posts: 27
Question Problem in fetch first n rows in DB2

Hi,
I changed rownum by "fetch first n rows" only. But i am passing this n value as one param in my procedure. How can we write fetch first..... in this

I tried it like this, but its showing error

CREATE VIEW DBO.Step45_Flap1 AS
SELECT time_stamp FROM ( SELECT time_stamp FROM(
SELECT time_stamp FROM (SELECT time_stamp' ||CHAR(query1)||' FROM '||Param5||' GROUP BY time_stamp ORDER BY time_stamp DESC) WHERE time_stamp '||CHAR(Param4)||' TIMESTAMP_FORMAT(Param3,''YYYY-MM-DD HH24:MIS'') FETCH FIRST'||CHAR(Param6)||'ROWS ONLY)
ORDER BY time_stamp ASC) FETCH FIRST'||CHAR(Param7)'ROWS ONLY';


Error is:

DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601, SQLERRMC: 'ROW ONLY';FIRST'||CHAR(Param7);<space>

Thanks in Advance
Vivek
Reply With Quote
  #2 (permalink)  
Old 01-22-09, 05:26
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
is this create view statement part of a procedure or how are they linked
in a regular view there are no parameters, so param6 is handled as a column name - that is why the 104 error, because this clmn does not exists
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #3 (permalink)  
Old 01-22-09, 05:29
vivek.vivek vivek.vivek is offline
Registered User
 
Join Date: Jan 2009
Posts: 27
I converted that from:

CREATE OR REPLACE VIEW Step45_Flap1 AS
SELECT time_stamp FROM ( SELECT time_stamp FROM(
SELECT time_stamp FROM (SELECT time_stamp' ||query1||' FROM '||Param5||' GROUP BY time_stamp ORDER BY time_stamp DESC) WHERE time_stamp '||Param4||' TO_DATE('''||Param3||''',''MM/DD/YYYY HH24:MIS'') AND ROWNUM<='||Param6||')
ORDER BY time_stamp ASC) WHERE ROWNUM<='||Param7;
Reply With Quote
  #4 (permalink)  
Old 01-22-09, 05:32
vivek.vivek vivek.vivek is offline
Registered User
 
Join Date: Jan 2009
Posts: 27
Ok Sir, it got executed. I missed one concat symbol '||'
before: FETCH FIRST'||CHAR(Param7)'ROWS ONLY'
after
FETCH FIRST'||CHAR(Param7)||'ROWS ONLY'
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On