Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2009
    Posts
    27

    Question Unanswered: 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

  2. #2
    Join Date
    Apr 2006
    Location
    Belgium
    Posts
    2,514
    Provided Answers: 11
    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
    Good DBAs are not formed in a week or a month. They are created little by little, day by day. Protracted and patient effort is needed to develop good DBAs.
    Spoon feeding : To treat (another) in a way that discourages independent thought or action, as by overindulgence.
    DB2 UDB LUW Certified V7-V8-V9-V9.7-V10.1-V10.5 DB Admin - Advanced DBA -Dprop..
    Information Server Datastage Certified
    http://www.infocura.be

  3. #3
    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;

  4. #4
    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'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •