Exlcuding data from SQL table in query

I may have been working too many hours lately, or I'm simply losing my mind, but I'm having a heck of a time with a very strange result from a query
I have a simple query that retrieves emails from a list
SELECT emaillist_email
FROM emaillist
Now let's say the above gives 50,000 records
Now take this
SELECT emaillist_block_email
FROM emaillist_block
Say that gives 5,000 records
Now put them together
SELECT emaillist_email
FROM emaillist
WHERE emaillist_email NOT IN
SELECT emaillist_block_email
FROM emaillist_block
Now unless I am losing it, I should get 45,000 records, presuming that the 5,000 are in both tables.
The issue is, I get zero records.
Any ideas?
*** I Have solved the problem after digging a little deeper. There was a NULL record in the data which had been imported from XLS causing it to throw the query out, once I removed it the correct records were returned ***

While you got your answer, using "not in" slows down queries.  Something like this would be faster.
SELECT emaillist_email
FROM emaillist eml
WHERE not exists
(select *
from emaillist_block emb
where emb.emailllist_block_email = eml.emaillist_email)
Or better yet,
alter table emaillist_email add column isBlocked bit default 0

Similar Messages

  • Pull data from SQL Table and display it in mail

    I have a requirement to pull the data from SQL table and send it in email.  Currently I am sending the hard coded info in email but is it possible to pull some data from SQL Table and than format it and send it across in the same email? 
    Can you guide me with steps on this.
    Neil

    There are several ways to do this.  First is to populate a file in a data flow and then send that as an attachment in the send mail task. 
    As far as including the results in the email body this becomes a bit trickier.  To use a variable you would need to use an SSIS variable type of
    Object, this is similar to a collection in .NET.  The problem once the object is populated is that it isn't like a readable result set, but again more like an array or a collection.  There is no native method to take the object variable and
    specify .ToString() or cast its results as text.  You would need to iterate through each row and append it to another variable of type string, this could be done with a script task or ForEach container.
    Also you mentioned formatting the results.  What type of formatting were you looking for.  A limitation of the SMTP send mail task is that the message body doesn't support HTML so if you were looking at creating a table within the mail body you
    would have to use a script task or a custom component
    David Dye My Blog

  • To retrieve data from sql table and pass to SAP

    Dear expert,
    My company is using e-store, customers place order thru the web, these orders are stored in sql server
    Now I want to retrieve this data then call BAPI to create sales order in SAP.
    What is the proper way ? RFC or DBCON ? Can RFC call BAPI ? I'm not familiar with RFC/DBCON.
    Please let me know how to do that ? Would appreciate if there is any sample given.
    Thanks

    Few Nice Blogs .
    Using ABAP to access non-SAP databases
    Installing DB Connect with MSSQL Server Database
    Thanks to Tony and Graham Robbo.

  • Select query taking too much time to fetch data from pool table a005

    Dear all,
    I am using 2 pool table a005 and a006 in my program. I am using select query to fetch data from these table. i.e. example is mentioned below.
    select * from a005 into table t_a005 for all entries in it_itab
                       where vkorg in s_vkorg
                       and     matnr in  s_matnr
                       and     aplp   in  s_aplp
                       and     kmunh = it_itab-kmunh.
    here i can't create index also as tables are pool table...If there is any solutions , than please help me for same..
    Thanks ,

    it would be helpful to know what other fields are in the internal table you are using for the FOR ALL ENTRIES.
    In general, you should code the order of your fields in the select in the same order as they appear in the database.  If you do not have the top key field, then the entire database is read. If it's large then it's going to take a lot of time.  The more key fields from the beginning of the structure that you can supply at faster the retrieval.
    Regards,
    Brent

  • In PL-SQL archive data from a table to a file

    I am currently developing a vb app where I need to archive data from a table to a file. I was hoping to do this with a stored procedure. I will also need to be able to retrieve the data from the file for future use if necessary. What file types are available? Thanks in advance for any suggestions.

    What about exporting in an oracle binary format? The export files cannot be modifiable. Is there a way to use the export and import utility in PL/SQL?
    null

  • How to Export data from a Table to Excel using PL/SQL Code

    Hi,
    I need to export data from a table to the excel sheet using PL/SQL script.
    could you pls provide with custom codes or sample procedures.
    Bobby

    http://asktom.oracle.com/pls/ask/f?p=4950:8:7947129213057862756::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:728625409049

  • Using Oracle Forms Importing Data From SQL Server into Oracle Tables.

    Dear All,
    We are using Oracle Forms 10g in windows XP and having OAS 10g and Oracle database 9i.
    How can we import data from SQL Server 2005 into Oracle tables using Oracle Forms?
    Thanks & Regards
    Eidy

    I have no idea what "Oracle Hetrogenius Services" is, so I can't help you with that, sorry.
    SQL Developer might also assist you. SQL Developer can connect to SQL Server as well as Oracle and has some tools for migration. See the documentation for details:
    http://download.oracle.com/docs/cd/E12151_01/doc.150/e12156/toc.htm
    For additional help on using SQL Developer for this task, please consult Support or the SQL Developer forum: SQL Developer
    Hope this helps,
    Jacob

  • Fetch the data from the tables in the SQL 2005 server to sap R/3.

    Hi Experts,
    We need to fetch the data from the tables in the SQL 2005 server to sap R/3.
    Please explain which will be the best approach to fetch the same and how to do it. Sample program can greatly help.
    << Please do not offer points >>
    Regards,
    Shobana K
    Edited by: Rob Burbank on Sep 21, 2010 2:36 PM

    Hi,
    Try NATIVE SQL statements in your abap code otherwise you can try to establish jdbc connection from ABAP program.
    search in SDN for samples!
    Suresh

  • Transfer data from SAP TABLES to a SQL table

    Hi,
    I need to transfer data from SAP tables to a SQL table. Please suggest the best way as well as the steps please.
    Regards,
    Kamlesh

    Hi
    Step 1: Create an entry for the External database in DBCON table using Trxn: DBCA.
    Field Name Description Value (For: E.g.:)
    CON_NAME Logical name
    for database con RAJ
    DBMS Database system MSS
    USER_NAME Database user <username>
    PASSWORD Password for setting up
    the connection
    to the database <pwd>/<pwd>
    CON_ENV Database-specific MSSQL_SERVER=depotserver MSSQL_DBNAME=HOF_INDORE
    DB_RECO Availability type for an open database connect
    Then, you can define internal table and code the following way:
    DATA: BEGIN OF wa,
    c_locid(3),
    c_locname(50),
    c_locstate(5),
    END OF wa.
    EXEC SQL.
    CONNECT TO 'RAJ' AS 'V'
    ENDEXEC.
    EXEC SQL.
    SET CONNECTION 'V'
    ENDEXEC.
    < Populate SAP data into an internal table >
    Loop on itab.
    EXEC SQL.
    < code here for populating data into MS-SQL Server table>
    ENDEXEC.
    Endloop.
    Regards,
    Raj

  • How to extract incremental data from SQL server to oracle tables in ODI

    HI All,
    In my ODI sql server is install.My Source is in SQL server and my target is in Oracle.
    I need to create a interface mapping where i need to extract incremental data from sql server to oracle.
    There is a datetime(with Timestamp) field in sql server .I need to pull incremental data based on dateime.
    Example = tablename.DateTime > (select '1-jan-11' from dual) .....i am using this query but its not woking.the error is Invalid object name"dual".
    We are not going to use Incremental in IKM and LKM.
    Request you to please provide any suggestion ASAP.
    Thanks,
    Lony

    You can do that via Variable.
    In the interface mapping create a filter on Tablename.DateTime
    and put the condition like this
    Tablename.DateTime BETWEEN #VAR and in the variable use this query in refreshing tab with oracle schema
    SELECT max(start_time)||' AND '||max(END_TIME)+1 from audit_table where ETL_JOB_CODE = '20'In the package call the above variable in refresh mode and then interface.
    This way you will pass from the query between and condition date and pass to interface so that SQL Server fetches the data between those too range.
    Note:- You might need to tweak the date format so that SQL Server can understand.
    Hope this helps.

  • How to select data from Sql server 2005 database tableinto oracle database table

    Hi,
    I have table text1 in sql server database and text2 in oracle database (11g). Now how to move data from SQL Server table into oracle table. So please help me how to do it.
    Thanks a lot in advance.
    rk
    OS: Windows 7 professional

    Hi,
    you can use export/import wizard and specify sql server as a source and oracle as destination.
    I hope this is helpful.
    Please Mark it as Answered if it answered your question
    OR mark it as Helpful if it help you to solve your problem
    Elmozamil Elamir Hamid
    MCSE Data Platform
    MCITP: SQL Server 2008 Administration/Development
    MCSA SQL Server 2012
    MCTS: SQL Server Administration/Development
    MyBlog

  • The SQL statement is not valid - when importing data from SQL Server using a query

    Hi there,
    I am trying to import data from SQL to Power Pivot using a SQL query like below:
    SELECT Score.FieldCount, Score.Record.GetAt(0), Score.Record.GetAt(1),  Score.Record.GetAt(2),  Score.Record.GetAt(3),  Score.Record.GetAt(4)
    FROM 
    SELECT * FROM dbo.CLR1(
    dbo.CLR2('c:\FILES\Test.xml'), 
    'SELECT * FROM [dbo].[CXCustomer_Small]') Input
    ) Score
    And when I tried to validate it, it returns
    The SQL statement is not valid. A column name cannot be blank.
    I ran the above SQL statement in Management Studio and it works without problem. Any idea?
    Thanks!
    Chu
    -- Predict everything. http://www.predixionsoftware.com

    Never mind, I figured out - I need to give each column a name.
    -- Predict everything. http://www.predixionsoftware.com

  • SQL Select Performance - Approached to fetch data from big table

    Hi
    I just wanted to know view on different approached to fetch data from a table which has 40 billion records and which joined to another table which has 1 million record.
    e.g.
    I have two tables TableA and TableB
    TableA has 40 Billion records has 6 columns
         TableA has partitions on Date
         TableA has required indexes
    TableB has 1 Milluion record and has 10 columns
         Table A has indexes
    Now I have written query like
    select distinct TableA.column1,TableA.column2,TableB.columnA
    FROM TableA join TableB
    ON TableA.Column1=TableB.Column2
    WHERE TableA.DateColumn between StartDate and EndDate
    for a given date range it will fetch 5 billion of records which takes around 40 minutes.
    I just wanted to know what all tuning approaches I can follow. What would be the best approach to make record retrieval faster in such a scenario.
    Just wanted to know your vies/experience in such a scenario

    Sufficiently large array fetchsize
    and,
    possibly using parallel query,
    pop into my mind.
    I would be interested though in the business requirement that asks for you to write a program that gets 5 billion (!) rows out of the database...

  • Copying large amount of data from one table to another getting slower

    I have a process that copies data from one table (big_tbl) into a very big archive table (vb_archive_tbl - 30 mil recs - partitioned table). If there are less than 1 million records in the big_tbl the copy to the vb_archive_table is fast (-10 min), but more importantly - it's consistant. However, if the number of records is greater than 1 million records in the big_tbl copying the data into the vb_archive_tbl is very slow (+30 min - 4 hours), and very inconsistant. Every few days the time it takes to copy the same amount of data grows signicantly.
    Here's an example of the code I'm using, which uses BULK COLLECT and FORALL INSERST to copy the data.
    I occasionally change 'LIMIT 5000' to see performance differences.
    DECLARE
    TYPE t_rec_type IS RECORD (fact_id NUMBER(12,0),
    store_id VARCHAR2(10),
    product_id VARCHAR2(20));
    TYPE CFF_TYPE IS TABLE OF t_rec_type
    INDEX BY BINARY_INTEGER;
    T_CFF CFF_TYPE;
    CURSOR c_cff IS SELECT *
    FROM big_tbl;
    BEGIN
    OPEN c_cff;
    LOOP
    FETCH c_cff BULK COLLECT INTO T_CFF LIMIT 5000;
    FORALL i IN T_CFF.first..T_CFF.last
    INSERT INTO vb_archive_tbl
    VALUES T_CFF(i);
    COMMIT;
    EXIT WHEN c_cff%NOTFOUND;
    END LOOP;
    CLOSE c_cff;
    END;
    Thanks you very much for any advice
    Edited by: reid on Sep 11, 2008 5:23 PM

    Assuming that there is nothing else in the code that forces you to use PL/SQL for processing, I'll second Tubby's comment that this would be better done in SQL. Depending on the logic and partitioning approach for the archive table, you may be better off doing a direct-path load into a staging table and then doing a partition exchange to load the staging table into the partitioned table. Ideally, you could just move big_tbl into the vb_archive_tbl with a single partition exchange operation.
    That said, if there is a need for PL/SQL, have you traced the session to see what is causing the slowness? Is the query plan different? If the number of rows in the table is really a trigger, I would tend to suspect that the number of rows is causing the optimizer to choose a different plan (with your sample code, the plan is obvious, but perhaps you omitted some where clauses to simplify things down) which may be rather poor.
    Justin

  • How to delete the data from partition table

    Hi all,
    Am very new to partition concepts in oracle..
    here my question is how to delete the data from partition table.
    is the below query will work ?
    delete from table1 partition (P_2008_1212)
    we have define range partition ...
    or help me how to delete the data from partition table.
    Thanks
    Sree

    874823 wrote:
    delete from table1 partition (P_2008_1212)This approach is wrong - as Andre pointed, this is not how partition tables should be used.
    Oracle supports different structures for data and indexes. A table can be a hash table or index organised table. It can have B+tree index. It can have bitmap indexes. It can be partitioned. Etc.
    How the table implements its structure is a physical design consideration.
    Application code should only deal with the logical data structure. How that data structure is physically implemented has no bearing on application. Does your application need to know what the indexes are and the names of the indexes,in order to use a table? Obviously not. So why then does your application need to know that the table is partitioned?
    When your application code starts referring directly to physical partitions, it needs to know HOW the table is partitioned. It needs to know WHAT partitions to use. It needs to know the names of the partitions. Etc.
    And why? All this means is increased complexity in application code as this code now needs to know and understand the physical data structure. This app code is now more complex, has more moving parts, will have more bugs, and will be more complex to maintain.
    Oracle can take an app SQL and it can determine (based on the predicates of the SQL), which partitions to use and not use for executing that SQL. All done totally transparently. The app does not need to know that the table is even partitioned.
    This is a crucial concept to understand and get right.

Maybe you are looking for