SBO SQL Query outputs zero values as nulls but need the zeros

Hi all,
I'm having a problem with a query I'm writing in SBO where if the field contents are zero, these are output as null.
I have a field for the stock usage on sales orders and ont too for production orders, but if I add these together they only provide a result if both columns contain a numeric value.
I've tried adding "0" to the column value, adding and subtracting "1" and also multiplying the value by "1" but still no joy.
I have also tried adding a "cast" statement to the column, but that doesnt seem to have an effect either (I think as this is more an output function).
I need to be able to use these columns as separate displays in addition to being used in a further column as part of a calculation.
If anyone has an idea how I can output a true zero value as opposed to a null value your help would be appreciated.
Cheers,
J

Hello Julian,
You could try to use a CASE Statement as I have shown below and test this will the SQL below.  If you use the T0.LineNum without any CASE or CAST the LineNum 0 will show as blank in SAP.
SELECT
CASE WHEN T0.LineNum != 0 THEN CAST(T0.LineNum AS VARCHAR(10)) ELSE '0' END AS 'Row Number',
T0.ItemCode AS 'Item No.', T0.BaseQty AS 'Base Quantity', T0.PlannedQty AS 'Planned Quantity - Rows'  FROM  [dbo\].[WOR1\] T0

Similar Messages

  • How could I replace hard coded value in my sql query with constant value?

    Hi all,
    Could anyone help me how to replace hardcoded value in my sql query with constant value that might be pre defined .
    PROCEDURE class_by_day_get_bin_data
         in_report_parameter_id   IN   NUMBER,
         in_site_id               IN   NUMBER,
         in_start_date_time       IN   TIMESTAMP,
         in_end_date_time         IN   TIMESTAMP,
         in_report_level_min      IN   NUMBER,
         in_report_level_max      IN   NUMBER
    IS
      bin_period_length   NUMBER(6,0); 
    BEGIN
      SELECT MAX(period_length)
         INTO bin_period_length
        FROM bin_data
         JOIN site_to_data_source_lane_v
           ON bin_data.data_source_id = site_to_data_source_lane_v.data_source_id
         JOIN bin_types
           ON bin_types.bin_type = bin_data.bin_type 
       WHERE site_to_data_source_lane_v.site_id = in_site_id
         AND bin_data.start_date_time     >= in_start_date_time - numtodsinterval(1, 'DAY')
         AND bin_data.start_date_time     <  in_end_date_time   + numtodsinterval(1, 'DAY')
         AND bin_data.bin_type            =  2
         AND bin_data.period_length       <= 60;
      --Clear the edr_class_by_day_bin_data temporary table and populate it with the data for the requested
      --report.
      DELETE FROM edr_class_by_day_bin_data;
       SELECT site_to_data_source_lane_v.site_id,
             site_to_data_source_lane_v.site_lane_id,
             site_to_data_source_lane_v.site_direction_id,
             site_to_data_source_lane_v.site_direction_name,
             bin_data_set.start_date_time,
             bin_data_set.end_date_time,
             bin_data_value.bin_id,
             bin_data_value.bin_value
        FROM bin_data
        JOIN bin_data_set
          ON bin_data.bin_serial = bin_data_set.bin_serial
        JOIN bin_data_value
          ON bin_data_set.bin_data_set_serial = bin_data_value.bin_data_set_serial
        JOIN site_to_data_source_lane_v
             ON bin_data.data_source_id = site_to_data_source_lane_v.data_source_id
            AND bin_data_set.lane = site_to_data_source_lane_v.data_source_lane_id
        JOIN (
               SELECT CAST(report_parameter_value AS NUMBER) lane_id
                 FROM report_parameters
                WHERE report_parameters.report_parameter_id    = in_report_parameter_id
                  AND report_parameters.report_parameter_group = 'LANE'
                  AND report_parameters.report_parameter_name  = 'LANE'
             ) report_lanes
          ON site_to_data_source_lane_v.site_lane_id = report_lanes.lane_id
        JOIN (
               SELECT CAST(report_parameter_value AS NUMBER) class_id
                 FROM report_parameters
                WHERE report_parameters.report_parameter_id    = in_report_parameter_id
                  AND report_parameters.report_parameter_group = 'CLASS'
                  AND report_parameters.report_parameter_name  = 'CLASS'
             ) report_classes
          ON bin_data_value.bin_id = report_classes.class_id
        JOIN edr_rpt_tmp_inclusion_table
          ON TRUNC(bin_data_set.start_date_time) = TRUNC(edr_rpt_tmp_inclusion_table.date_time)
       WHERE site_to_data_source_lane_v.site_id = in_site_id
         AND bin_data.start_date_time     >= in_start_date_time - numtodsinterval(1, 'DAY')
         AND bin_data.start_date_time     <  in_end_date_time   + numtodsinterval(1, 'DAY')
         AND bin_data_set.start_date_time >= in_start_date_time
         AND bin_data_set.start_date_time <  in_end_date_time
         AND bin_data.bin_type            =  2
         AND bin_data.period_length       =  bin_period_length;
    END class_by_day_get_bin_data;In the above code I'm using the hard coded value 2 for bin type
    bin_data.bin_type            =  2But I dont want any hard coded number or string in the query.
    How could I replace it?
    I defined conatant value like below inside my package body where the actual procedure comes.But I'm not sure whether I have to declare it inside package body or inside the procedure.
    bin_type     CONSTANT NUMBER := 2;But it does't look for this value. So I'm not able to get desired value for the report .
    Thanks.
    Edited by: user10641405 on May 29, 2009 1:38 PM

    Declare the constant inside the procedure.
    PROCEDURE class_by_day_get_bin_data(in_report_parameter_id IN NUMBER,
                                        in_site_id             IN NUMBER,
                                        in_start_date_time     IN TIMESTAMP,
                                        in_end_date_time       IN TIMESTAMP,
                                        in_report_level_min    IN NUMBER,
                                        in_report_level_max    IN NUMBER) IS
      bin_period_length NUMBER(6, 0);
      v_bin_type     CONSTANT NUMBER := 2;
    BEGIN
      SELECT MAX(period_length)
        INTO bin_period_length
        FROM bin_data
        JOIN site_to_data_source_lane_v ON bin_data.data_source_id =
                                           site_to_data_source_lane_v.data_source_id
        JOIN bin_types ON bin_types.bin_type = bin_data.bin_type
       WHERE site_to_data_source_lane_v.site_id = in_site_id
         AND bin_data.start_date_time >=
             in_start_date_time - numtodsinterval(1, 'DAY')
         AND bin_data.start_date_time <
             in_end_date_time + numtodsinterval(1, 'DAY')
         AND bin_data.bin_type = v_bin_type
         AND bin_data.period_length <= 60;
      --Clear the edr_class_by_day_bin_data temporary table and populate it with the data for the requested
      --report.
      DELETE FROM edr_class_by_day_bin_data;
      INSERT INTO edr_class_by_day_bin_data
        (site_id,
         site_lane_id,
         site_direction_id,
         site_direction_name,
         bin_start_date_time,
         bin_end_date_time,
         bin_id,
         bin_value)
        SELECT site_to_data_source_lane_v.site_id,
               site_to_data_source_lane_v.site_lane_id,
               site_to_data_source_lane_v.site_direction_id,
               site_to_data_source_lane_v.site_direction_name,
               bin_data_set.start_date_time,
               bin_data_set.end_date_time,
               bin_data_value.bin_id,
               bin_data_value.bin_value
          FROM bin_data
          JOIN bin_data_set ON bin_data.bin_serial = bin_data_set.bin_serial
          JOIN bin_data_value ON bin_data_set.bin_data_set_serial =
                                 bin_data_value.bin_data_set_serial
          JOIN site_to_data_source_lane_v ON bin_data.data_source_id =
                                             site_to_data_source_lane_v.data_source_id
                                         AND bin_data_set.lane =
                                             site_to_data_source_lane_v.data_source_lane_id
          JOIN (SELECT CAST(report_parameter_value AS NUMBER) lane_id
                  FROM report_parameters
                 WHERE report_parameters.report_parameter_id =
                       in_report_parameter_id
                   AND report_parameters.report_parameter_group = 'LANE'
                   AND report_parameters.report_parameter_name = 'LANE') report_lanes ON site_to_data_source_lane_v.site_lane_id =
                                                                                         report_lanes.lane_id
          JOIN (SELECT CAST(report_parameter_value AS NUMBER) class_id
                  FROM report_parameters
                 WHERE report_parameters.report_parameter_id =
                       in_report_parameter_id
                   AND report_parameters.report_parameter_group = 'CLASS'
                   AND report_parameters.report_parameter_name = 'CLASS') report_classes ON bin_data_value.bin_id =
                                                                                            report_classes.class_id
          JOIN edr_rpt_tmp_inclusion_table ON TRUNC(bin_data_set.start_date_time) =
                                              TRUNC(edr_rpt_tmp_inclusion_table.date_time)
         WHERE site_to_data_source_lane_v.site_id = in_site_id
           AND bin_data.start_date_time >=
               in_start_date_time - numtodsinterval(1, 'DAY')
           AND bin_data.start_date_time <
               in_end_date_time + numtodsinterval(1, 'DAY')
           AND bin_data_set.start_date_time >= in_start_date_time
           AND bin_data_set.start_date_time < in_end_date_time
           AND bin_data.bin_type = v_bin_type
           AND bin_data.period_length = bin_period_length;
    END class_by_day_get_bin_data;

  • SQL query to get last 6 months records neglect the current month

    Hi All;
    I need help with 
    sql query to get last 6 months records neglect the current month
    Any help much appreciated
    Thanks
    Pradnya07

    SELECT <> FROM tbl WHERE dt >=dateadd(month,-6,GETDATE())
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • SQL query can be executed through TOAD but not through Discoverer

    Hallo, everybody:
    Got another problem. A SQL query can be executed through TOAD, but when I want to execute it by a worksheet of Discoverer Plus, it always shows there is no data.
    PS: I copied this query from Discoverer Plus to TOAD, which means, this query is generated through the Discoverer. Does anybody know about how could it be?
    Thank you.
    Geng

    Hi,
    If you are able to get data in TOAD with the same user credential as that of Discoverer Plus then it will implies an issue with Discoverer.
    Else it is privilege issue , your TOAD user has select privilege to the base objects (tables/views etc) where as your Disoverer used does not.
    Compare the privileges granted to these 2 users and you can narrow done to the issue .
    Thanks,
    Sutirtha

  • Writing a function to find whether a value is present in a sql query output

    Hi gurus,
    I would like to write a function to which i will pass a value and a sql query as parameters.
    Now the function needs to execute that sql query and find whether the given value is present in the output list
    when the query is executed. If it is present it should return 'T' otherwise 'F'
    My function will look like
    CREATE FUNCTION CHECK_VALUE(VALUE VARCHAR2,V_SQL VARCHAR2) RETURN VARCHAR2
    SELECT CHECK_VALUE('Dallas','SELECT LOCATION_CODE FROM HR_LOCATIONS')
    It should check whether the value 'Dallas' is present in the output list returned by the sql query.
    Any help will be appreciated.
    Thank you.

    CREATE OR REPLACE
      FUNCTION CHECK_VALUE(
                           VALUE VARCHAR2,
                           V_SQL VARCHAR2
        RETURN VARCHAR2
        IS
            RETVAL VARCHAR2(4000);
            REFCUR SYS_REFCURSOR;
        BEGIN
            OPEN REFCUR FOR V_SQL;
            LOOP
              FETCH REFCUR INTO RETVAL;
              EXIT WHEN REFCUR%NOTFOUND;
              IF RETVAL = VALUE
                THEN
                  CLOSE REFCUR;
                  RETURN 'T';
              END IF;
            END LOOP;
            CLOSE REFCUR;
            RETURN 'F';
    END;
    Function created.
    SQL> SET SERVEROUTPUT ON
    SQL> EXEC DBMS_OUTPUT.PUT_LINE(CHECK_VALUE('DALLAS','select loc from dept'));
    T
    PL/SQL procedure successfully completed.
    SQL> EXEC DBMS_OUTPUT.PUT_LINE(CHECK_VALUE('PARIS','select loc from dept'));
    F
    PL/SQL procedure successfully completed.
    SQL> SY.

  • SQL query - Alias name (value) as parameter to an Oracle function

    Hi,
    I have a sql query something like
    Select tbl1.valueA, tbl1.valueB, tbl2.valueX, MAX(CASE tbl2.valueY = 'XX' THEN tbl2.valueZ END) AS "ValueZ header", Function(tbl1.valueB, tbl2.valueX, "valueZ header")
    FROM table1 tbl1
    JOIN table2 tbl2 ON tbl1.id = tbl2.tbl1id
    WHERE ...
    my problem is that I need the value from MAX statement as parameter to the function and I have tried to use the alias name (valueZ header) but this is not working. I guess because of some syntax error. Can I use alias name as parameter into the function at all - if - how should I do this?

    Hi,
    user8819407 wrote:
    Hi,
    I have a sql query something like
    Select tbl1.valueA, tbl1.valueB, tbl2.valueX, MAX(CASE tbl2.valueY = 'XX' THEN tbl2.valueZ END) AS "ValueZ header", Function(tbl1.valueB, tbl2.valueX, "valueZ header")
    FROM table1 tbl1
    JOIN table2 tbl2 ON tbl1.id = tbl2.tbl1id
    WHERE ...
    my problem is that I need the value from MAX statement as parameter to the function and I have tried to use the alias name (valueZ header) but this is not working. I guess because of some syntax error. Can I use alias name as parameter into the function at all - if - how should I do this?You can use a column alias in the ORDER BY clause of the same query where it was defined, but that's the only place where you can use it in that query.
    You could repeat the entire MAX (CASE ...) expression as the 3rd argumnet to your function, or you could compute it once in a sub-query, then reference the column alias as often as you like in the super-query, like this:
    WITH     got_valuez_header     AS
         Select  tbl1.valueA
         ,     tbl1.valueB
         ,     tbl2.valueX
         ,     MAX ( CASE
                            WEHN  tbl2.valueY = 'XX'     -- Don't forget the keyword WHEN
                      THEN      tbl2.valueZ
                    END
                  )          AS "ValueZ header"
         FROM         table1     tbl1
         JOIN         table2     tbl2     ON     tbl1.id     = tbl2.tbl1id
         WHERE          ...
         GROUP BY     ...
    Select  tbl1.valueA
    ,     tbl1.valueB
    ,     tbl2.valueX
    ,     "ValueZ header"
    ,     Function_x ( tbl1.valueB     -- FUNCTION is not a good name for a function
                 , tbl2.valueX
                 , "ValueZ header"     -- Case-sensitive
    FROM    got_valuez_header
    ;

  • SQL query for updating values in same cell of a table

    Hi All,
    I'm stuck with a problem and it stands as follows:
    Table name: Track
    Part1  Part2  Part3
    NULL   NULL   NULL
    I've a table called Track, which has three columns named Part1, Part2 and Part3. I want all values of Part1 to be separated by a comma (,); it should not be overwritten, neither they should appear in separate row, in fact they should look like this:
    Part1    Part2    Part3
    1,2,3    5          SUBM1
    The new values of Part1 should appear in next row only when value of Part3 changes, so if Part3 changes from SUBM1 to SUBM2, it should look like this:
    Part1    Part2    Part3
    1,2,3    5          SUBM1
    1,2,3    5          SUBM2
    Count of values in Part1 never exceeds the value of Part2, so if Part2 is 5, then Part1 will look like 1,2,3,4,5. So in other words loop will run only up to the value of Part2.
    Please advise how this could be achieved?
    Kind regards,
    Aniruddha Jagdale

    I've a table called Track, which has three columns named Part1, Part2 and Part3. I want all values of Part1 to be separated by a comma (,);
    No, don't go there.
    This breaks a fundamental point for relational databases: no repeating groups. A cell should hold an atomic value. And this is not only a matter of purism. Relational databases are designed from this principle, and breaking this means that you will need
    to write complex and higly inefficient code.
    The values in Part1 should be in a separate table, with one value per row.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • SQL query output

    Dear friends ,
    I want to view a select query using page by page . Is it possible to do in SQL ?
    suppose here is an example of select query :
    sql > select * from v$session ;
    I want to see the output as page by page .
    waiting for ur kind reply . .. ..

    Hi, (assuming you use Db 10g v.2)
    you should read the chapter "6 Formatting SQL*Plus Reports" of e-book:
    SQL*Plus® User's Guide and Reference
    Release 10.2
    Part Number B14357-01
    and especially the 'break' command.....
    Greetings,
    Sim

  • Inserting field text into sql query and comparing values to another table

    I have an issue in Visual Web Developer 2010 that I need help with.
    The code below is a Gridview Sql query where I'm extracting PART_NUMBER from various tables.  I would like to add the table name in a separate field named Table.  The end result should appear as follows:
    PART_NUMBER     Table
    010-0075-06       Resistors (or Capacitors, etc.)
    Sql query:
    SELECT     PART_NUMBER
    FROM         Capacitors
    EXCEPT
    SELECT     PART_NUMBER
    FROM         [CIS Manufacturer Parts]
    UNION
    SELECT     PART_NUMBER
    FROM         Connectors
    EXCEPT
    SELECT     PART_NUMBER
    FROM         [CIS Manufacturer Parts]
    UNION
    SELECT     PART_NUMBER
    FROM         Diodes
    EXCEPT
    SELECT     PART_NUMBER
    FROM         [CIS Manufacturer Parts]
    UNION
    SELECT     PART_NUMBER
    FROM         ICs
    EXCEPT
    SELECT     PART_NUMBER
    FROM         [CIS Manufacturer Parts]
    UNION
    SELECT     PART_NUMBER
    FROM         Inductors
    EXCEPT
    SELECT     PART_NUMBER
    FROM         [CIS Manufacturer Parts]
    UNION
    SELECT     PART_NUMBER
    FROM         Misc
    EXCEPT
    SELECT     PART_NUMBER
    FROM         [CIS Manufacturer Parts]
    UNION
    SELECT     PART_NUMBER
    FROM         Relays
    EXCEPT
    SELECT     PART_NUMBER
    FROM         [CIS Manufacturer Parts]
    UNION
    SELECT     PART_NUMBER
    FROM         Resistors
    EXCEPT
    SELECT     PART_NUMBER
    FROM         [CIS Manufacturer Parts]
    UNION
    SELECT     PART_NUMBER
    FROM         Switches
    EXCEPT
    SELECT     PART_NUMBER
    FROM         [CIS Manufacturer Parts]
    UNION
    SELECT     PART_NUMBER
    FROM         Transformers
    EXCEPT
    SELECT     PART_NUMBER
    FROM         [CIS Manufacturer Parts]
    UNION
    SELECT     PART_NUMBER
    FROM         Transistors
    EXCEPT
    SELECT     PART_NUMBER
    FROM         [CIS Manufacturer Parts]
    UNION
    SELECT     PART_NUMBER
    FROM         [Crystals and Oscillators]
    EXCEPT
    SELECT     PART_NUMBER
    FROM         [CIS Manufacturer Parts]
    ORDER BY PART_NUMBER
    I have a separate table (CIS Manufacturer Parts) that contains manufacturer data for the above parts.  Multiple manufacturer rows can exist.  The connection between tables in the PART_NUMBER field.  What I would like to do is make this query
    add the table name to the gridview output listing only parts without manufacturer data and the table they can be found in.
    This is a lot for a newbie so I will appreciate any help, thanks!

    Hello Bulldog248,
    Thank you for your post.
    Your issue is out of support range of VS General Question forum which mainly discusses the usage issue of Visual Studio IDE such as
    WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System
    and Visual Studio Editor.
    I am moving your question to the moderator forum ("Where is the forum for..?"). The owner of the forum will direct you to a right forum.
    Best regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Formatting SQL Query output in HTMLDB

    Guys, I would like to show the result in report of SQL Query to be formatted in such way:
    I got a table USERS with columns:FIrst_name, second_name, team_name, team_leader.
    So in a report in HTMLDB I would like to format the result to show all employees , 500 of them, on 1 page, and show in a header for each team, team leader and team name with the rest of team underneath,so only two columns, break on team_leader or team_name, then next team, and then, NOT all this in one long display, but in three sets of result, spread in wide of report, cause the screen dimensions are quite wide.I tried few things but they do not work. I can break on tem leader or team name, but all this is still in one long set of result, not in 3 or 4 tables sets.
    help
    Jozef

    Hi Kamal,
    I am using Oracle Applications 11.5.7 iProcurement. Database is 9i. I need to place a link in iProcurement homepage using AK Developer and when clicked it should run a query and output the result in a browser.
    help appreciated
    thanks

  • Need help in SQL Query: Update a row in a table & insert the same row into another table

    I want to update a row in a table say Table A and the updated row should be inserted into another table say Table B. I need to do it in a single SQL query and i don't want to do it in PL/SQL with triggers. And i tried with MERGE statement but its working with this scenario. (Note: I'm using Oracle Database 10g Enterprise Edition Release 10.2.0.1.0).
    Thanks in Advance.

    Using Sven's code as an example, you could save the updated row in a sql plus variable. (also untested):
    SQL> var v_id number
    update tableA  
    set colB='ABC' 
    where colC='XYZ' 
    returning id into :v_id;
    insert into table A_History (ID, colA, colB, ColC)  
    select id, ColA, ColB, ColC  
    from tableA  
    where id = :v_id;   

  • SQL Query if or case omit fields but not line.

    I have the below SQL Query my goal is to not show Aging or Storage Date if QTY is greater than 0. 
    I know I can omit the line but I still want to show just not those two fields is this possible?
    Select sl.SKU, sl.LOC, (editdate) AS "Storage Date", CAST(sysdate-editdate AS DECIMAL(10,2)) AS Aging, sl.QTY, sl.QTYALLOCATED
    From skuxloc sl
    Where sl.SKU in ('315A6112-29','315A6112-33')
    This is what I'm looking for:
    Work Smarter Not Harder

    Are you working with OracleSQL, There is no sysdate in SQL Server.
    Select sl.SKU, sl.LOC,
    case when sl.QTY =0 then '' else editdate end AS 'Storage Date',
    case when sl.QTY =0 then '' else CAST(sysdate-editdate AS DECIMAL(10,2)) END
    AS Aging,
    sl.QTY, sl.QTYALLOCATED
    From skuxloc sl
    Where sl.SKU in ('315A6112-29','315A6112-33')
    If you are working with Oracle, You can try decode.
    http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions040.htm
    http://www.dba-oracle.com/t_decode_function.htm
    --Prashanth

  • Query giving wrong values in portal but correct through RSRT

    Hi,
    Users are running a query through portal which is giving wrong figures. But when we are running the query through RSRT it is showing correct values. The quesry is built on top of an InfoCube which is regularly updated and data in it is matching with R/3.
    This is an Inventory Valuation Query.
    Please suggest what could be the possible issue.
    BR,
    Sayan

    Hi,
    Make sure cache is deleted for the particular query. While the report is executed through portal it refers the cache and if the data in the backend is not changed then the cache for a particular query selection is active and referred each time the query is run.
    on other hand while running RSRT we have an option of not using cache and thus it refers the infoprovider and fetches the correct result. In this case cache could be invalid.
    Try deleting the cache.
    Regards,
    Amit

  • Show SQL Query to be showed in Text object at the report

    Is there any way where I can take/copy the query showed in "Database->Show SQL Query" to be showed as a field in a TextBox inside the report.
    So it is a bit clearer what I am trying to do, it is to get who, when and what runs that report.
    Thanks in advance
    Tonio

    Hi Toni,
    I am not sure if I have understood your requirement. If you could elaborate what you are trying to do then i may be able to help.
    I understand you want to copy the query which is displayed in DATABASE->Show query name... I hope u are refering to SQ01 trx...
    I am not sure what next part..
    Rgds
    Abhijit

  • SQL query for zero or more than 1 row

    have 2 tables Table1 and Table2
    Table1 contains one varchar2 column Col1 with values: id1, id2, id3, id4, .....id9
    Table2 contains two varchar2 columns with values:
    Col1     Col2
    id1     some1
    id1     some2
    id3     some3
    id4     some4
    id9     some5
    id9     some6
    Table1 and Table2 join on Table1.col1 = Table2.col1
    I want to find those rows in Table1 that have zero or more than one values in Table2
    So the output in the above case would be
    id1 (since it has more than one corresponding values in Table2)
    id2 (since it does not have corresponding value in Table2)
    id9 (since it has more than one corresponding values in Table2)

    One way:
    select table1.col1
    from table1 left outer join table2 on table1.col1 = table2.col1
    group by table1.col1 having count(table2.col1) != 1
    Where there is no match, table2.col1 in the outer join will be null, so the count will be zero.
    Where there are multiple matches the count will be > 1.
    Untested because you didn't supply table and data creation scripts. See Re: 2. How do I ask a question on the forums?

Maybe you are looking for