Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9260565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:55:33+00:00 2026-06-18T12:55:33+00:00

I am using a AS400 DB2 Database. In that Database I got 3 Views.

  • 0

I am using a AS400 DB2 Database. In that Database I got 3 Views.

All Views have the exact same Columnnames and Datatypes.
View 1 & 2 each consist of a Select Statement with aggregate Functions on the same source Table. Just the WHERE Conditions and the aggregate Functions are a little different.

View 3 simply is a UNION SELECT on both VIEW 1 & 2 merging the results.

So here is my Question.

SELECT 2 AS CLIENT, COLUMN1, COLUMN2, COLUMN3, COLUMN4, VALUE 
FROM SOME_DATABASE.VIEW3
WHERE COLUMN1 = @COLUMN1 AND COLUMN2 = @COLUMN2 ORDER BY COLUMN3

I can execute parameterized SELECT Statements (like the one above) from my c# Program on VIEW 1 & 2 without problems, but when i try to use a parameterized SELECT on VIEW 3 I get a ‘SQL0901 SQL System Error.’ However, when i dont use Parameters it just works fine.

Can anyone explain this behaviour to me?

AS400 DB2 Version is v5r2m0
The program is written in c# on .NET 4.0 in VS 2012
using ‘IBM.Data.DB2.iSeries.dll’ for accessing the Database

Definition View 1:

SELECT  COLUMN1,  
        COLUMN2,  
        COLUMN3,  
        COLUMN4,  
        SUM(CAST((TRIM(SUBSTR(COLUMN5,104,1))||TRIM(SUBSTR(COLUMN5,94,3))||TRIM(SUBSTR(COLUMN5,98,3))||'.'||TRIM(SUBSTR(COLUMN5,102,2))) AS DECIMAL(10,2))) AS VALUE
FROM    SOME_DATABASE.SOME_TABLE  
WHERE   TRIM(SUBSTR(COLUMN5,105,3)) <> ''
AND     SUBSTR(COLUMN5,103,5) <> '  EUR'  
AND     COLUMN4 IN ('  $NEHHZ','$NEHHZVE','$NEHWMVE','  $NEHWW','$NEHWWVE','$NEHWWSK',' $NEHKW1',' $NEHKW2',' $NEHSK1',' $NEHSK2','  $NEHNV',' $NEHKZ1',' $NEHLZ1',' $NEHSZ1')  
GROUP BY  COLUMN1,  
        COLUMN2,  
        COLUMN3,  
        COLUMN4  

Definition View 2:

SELECT  COLUMN1,  
        COLUMN2,  
        COLUMN3,  
        COLUMN4,  
        SUM(CAST(TRIM(SUBSTR(COLUMN5,109,1))||TRANSLATE(TRIM(SUBSTR(COLUMN5,99,10)),'.',',') AS DECIMAL(10,2))) AS VALUE  
FROM    SOME_DATABASE.SOME_TABLE  
WHERE   COLUMN6 != 0  
AND     COLUMN4 IN (' SUM$HKV',' SUM$KWZ',' SUM$KZ',' SUM$LZ',' SUM$SZ',' SUM$WMZ',' SUM$WWZ')  
GROUP BY COLUMN1,  
        COLUMN2,  
        COLUMN3,  
        COLUMN4  

Definition View 3:

SELECT COLUMN1, COLUMN2, COLUMN3, COLUMN4, VALUE
FROM SOME_DATABASE.VIEW1
UNION
SELECT COLUMN1, COLUMN2, COLUMN3, COLUMN4, VALUE
FROM SOME_DATABASE.VIEW2
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:55:34+00:00Added an answer on June 18, 2026 at 12:55 pm

    It looks like parameterized SELECT Statements are not supported with views on views. I just replaced the 3rd View with a statement containing the definition of view 1 UNION view 2 like:

    SELECT  COLUMN1,  
            COLUMN2,  
            COLUMN3,  
            COLUMN4,  
            SUM(CAST((TRIM(SUBSTR(COLUMN5,104,1))||TRIM(SUBSTR(COLUMN5,94,3))||TRIM(SUBSTR(COLUMN5,98,3))||'.'||TRIM(SUBSTR(COLUMN5,102,2))) AS DECIMAL(10,2))) AS VALUE
    FROM    SOME_DATABASE.SOME_TABLE  
    WHERE   TRIM(SUBSTR(COLUMN5,105,3)) <> ''
    AND     SUBSTR(COLUMN5,103,5) <> '  EUR'  
    AND     COLUMN4 IN ('  $NEHHZ','$NEHHZVE','$NEHWMVE','  $NEHWW','$NEHWWVE','$NEHWWSK',' $NEHKW1',' $NEHKW2',' $NEHSK1',' $NEHSK2','  $NEHNV',' $NEHKZ1',' $NEHLZ1',' $NEHSZ1')  
    GROUP BY  COLUMN1,  
            COLUMN2,  
            COLUMN3,  
            COLUMN4
    
    UNION
    
    SELECT  COLUMN1,  
            COLUMN2,  
            COLUMN3,  
            COLUMN4,  
            SUM(CAST(TRIM(SUBSTR(COLUMN5,109,1))||TRANSLATE(TRIM(SUBSTR(COLUMN5,99,10)),'.',',') AS DECIMAL(10,2))) AS VALUE  
    FROM    SOME_DATABASE.SOME_TABLE  
    WHERE   COLUMN6 != 0  
    AND     COLUMN4 IN (' SUM$HKV',' SUM$KWZ',' SUM$KZ',' SUM$LZ',' SUM$SZ',' SUM$WMZ',' SUM$WWZ')  
    GROUP BY COLUMN1,  
            COLUMN2,  
            COLUMN3,  
            COLUMN4 
    

    And now it just works perfectly. But i still dont understand why this error occured.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an AS400 that we need to communicate with using our .NET applications.
I'm trying to connect to a AS400 server using the .net classes. I have
Ok So I have an AS400/iSeries running v5r4. I have an application that was
I’m using DB2 on AS400 (iSeries), hibernate 3, spring 2.0 and Java 6 and
I'm using pyodbc to query an AS400 (unfortunately), and some column names have hashes
We have a program on our AS400 that takes in a number, encrypts it
I have a database table that contains: Industry risk -------------- A B C And
Using SSRS 2008 R2 I have a background process that dynamically generates RDL for
I have a problem where in I have to call into the AS400 db2
Im using access 2003 to view some as400 tables and databases. I would need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.