Results 1 to 9 of 9

Thread: problem with sql query

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2017
    Posts
    19

    problem with sql query

    Hi

    I have a problem with datagrid1.
    Downloading data through Adodc1 but I can not add another column in which if in column1 I have 01 in the added column gives me 100 if 02 is 200, 03 is 500, 04 is 70
    The query from the database I have such
    Code:
    select SUBSTR (number, 1,2),
     SUM (ILOSC) FROM my data WHERE status = '200' AND city = 'Wroclaw' 
    GROUP BY SUBSTR (number, 1,2), ILOSC ORDER BY SUBSTR ( number, 1,2) ASC

  2. #2
    gibra
    Guest

    Re: problem with sql query

    Database you use? SQL Server, Oracle, Access, ...

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2017
    Posts
    19

    Re: problem with sql query

    Sorry!!
    Database Oracle

  4. #4
    gibra
    Guest

    Re: problem with sql query

    Then you can use CASE Expressions
    https://docs.oracle.com/cd/B19306_01...essions004.htm

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2017
    Posts
    19

    Re: problem with sql query

    I tried and I can not grasp

  6. #6
    Member
    Join Date
    Mar 2012
    Posts
    51

    Re: problem with sql query

    .....

  7. #7
    gibra
    Guest

    Re: problem with sql query

    Quote Originally Posted by ewcia87 View Post
    I tried and I can not grasp
    How did you try?
    Do you think we can guess it by ourselves?

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Sep 2017
    Posts
    19

    Re: problem with sql query

    Code:
    select SUBSTR (liczba, 1,2),SUMA (ILOSC),CASE SUBSTR(liczba,1,2) WHEN 01 THEN '100'WHEN 02 THEN '200'
    ELSE 'brak' END FROM my_data WHERE status = '200' AND city = 'Wroclaw' 
    GROUP BY SUBSTR (liczba, 1,2), ILOSC ORDER BY SUBSTR (liczba, 1,2) ASC

    receives a message
    ORA-00932 Error message
    Last edited by ewcia87; Feb 13th, 2018 at 05:08 PM.

  9. #9
    gibra
    Guest

    Re: problem with sql query

    You error because you try to compare different data type:

    https://www.techonthenet.com/oracle/errors/ora00932.php

    SUBSTR return a string data type, while 01 is NOT a string.
    Try to use '01' instead, and so on...

Posting Permissions

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



Click Here to Expand Forum to Full Width