Handling invalid Dates In query for Invalid dates in date column.

Hi,
I have a date column in my table. This column has corrupted data so the when i use any
to_timestamp function or any other date calcualtions my query breaks with the error:
ORA-01843: not a valid month.
I am aware the data is the issue.
But i want to handle this scenario by putting nulls in the output when ever an invalid date is encountered.
I have done some research and found the custom function is_date() on net.
But i am not suppose to create any new function but handle it with in my query.
Help is appreciated to handle this scenario.

Prasath wrote:
Try this!!
With Tab As(Select '12/01/2009' txt From dual)
SELECT Decode(Length(Replace(Translate( txt
, '0123456789/'
, Null
, to_date(txt,'mm/dd/yyyy')
, NULL) As Validation_date
FROM tab;
Ok ...
SQL> With Tab As(Select '12/01/2009' txt From dual)
  2      SELECT Decode(Length(Replace(Translate( txt
  3                                            , '0123456789/'
  4                                            , '#')
  5                                  ,'#'))
  6                   , Null
  7                   , to_date(txt,'mm/dd/yyyy')
  8                   , NULL) As Validation_date
  9       FROM tab;
VALIDATIO
01-DEC-09Not sure what that proves, especially in relation to the OP's problem.

Similar Messages

  • How to query for extended ASCII characters in column value

    Hi All
    Sorry if this has been answered before. I tried searching but none of them seems to work for me.
    I am trying to search for inverted ? in my column.
    I am using the following query
    select *
    from table_name
    where regexp_like (description , '¿' )

    Did you try:
    like '%¿%'
    create table table_name (description varchar2(100))
    insert into table_name values ('jh¿¿gagd')
    insert into table_name values ('jhga345gd')
    insert into table_name values ('j1231232hgagd¿')
    select *
    from table_name
    where regexp_like (description , '¿' )
    DESCRIPTION
    jh¿¿gagd
    j1231232hgagd¿
    select * from table_name
    where description like '%¿%'
    DESCRIPTION
    jh¿¿gagd
    j1231232hgagd¿Edited by: user130038 on Sep 8, 2011 12:29 PM

  • Handling DST in SQL Query for UCCX Custom Report

    We wrote all custom reports for one of the call centers using our UCCX deployment.  One problem we see we will hit in the future is DST.  We suggested they use UTC but they wanted to see the call data based off of EST timezone.  Right now we are okay because we use -5 to get the correct data but come March we are wondering how to address the issue.  What options do we have?  How are other people handling DST with the SQL queries for custom reporting?  I see that the HR client will determine this based off of the local computer time then gives you the option to use UTC.  We have all of our queries in an Excel document that the customer just needs to open and select Refresh All to update their data.
    Thanks

    "case-when" statements are evaluated in order.
    so you must do something like this:
    SELECT
    CASE WHEN <is not number>THEN 'N'
    CASE WHEN <is greater than 0>THEN 'Y'
    Now "<is greater than 0>" will always have number for input, can't get "not number" error there.
    See this thread:
    Re: regular expression: integer is between N..M
    Edited by: CharlesRoos on May 27, 2010 5:03 AM

  • Single query for displaying all but 1 column values for all tables

    Hi,
    All the tables have SYS_CREATION_DATE column.
    But I dont want to display this column value
    Can someone suggest some way in which i could achive this?
    Oracle version:11gR1
    OS:SunOS
    Cheers,
    Kunwar
    Edited by: user9131570 on Jul 6, 2010 7:57 PM

    user9131570 wrote:
    @Tubby
    I *want to display table-wise the values of all but 1(SYS_CREATION_DATE) columns in my database.*
    I need this in order to compare it to another database for all these values .Let me make a wild guess at what you are getting at.
    Given these two tables
    create table emp
       (empid number,
        empname varchar2(15),
        empaddr   varchar2(15),
        sys_creation_date date);
    create table dept
       (deptid number,
        deptmgr varchar2(10),
        sys_creation_date date);you want to somehow combine
    select empid,
             empname,
             empaddr
    from emp;with
    select deptid,
             deptmgr
    from dept;into a single sql statement?

  • GL Query for ACH demands a Blank Column

    This is a very basic question...
    I'm writing an SQL query to extract GL information from our Enterprise engine. The ACH format requires the format of the output file to include "filler" columns containing a single space.
    Using SQL I can extract all of the information. How do I add filler columns to the output of the Query?
    Eventually this will be spooled out to a file, encrypted and send to JPM Chase as a "check register".

    Your question seems to discuss a problem with EBS.
    The proper forum for EBS is General EBS Discussion
    In this forum, the RDBMS forum, you'll probably get no response at all.
    Sybrand Bakker
    Senior Oracle DBA

  • SQL Data Sync - column type invalid for use as a key column

    Hello,
    our sync group is failing to do the sync. Here's a tracingID:
    For more information, provide tracing ID ‘e3e568b5-140a-4ae5-a4c8-c178c6bf805d’ to customer support.
    I must say, that the column in DB is not a PK or INDEX-ed, it was initially VARCHAR(MAX), after some reading I changed it to VARCHAR(200) and later to TEXT, but the result of syncing is still the same.
    Thank you,
    Bojan

    Hi Bojan,
    The error “column type invalid for use as a key column” could be due to the existence of unsupported data types or column properties when implementing the synchronization. I recommend you check your database according to this article:
    SQL Database Data Types supported by SQL Data Sync.
    Besides, before you design and implement a data synchronization plan, please check the following articles about system requirements for SQL Data Sync and so on.
    System Requirements for SQL Data Sync
    https://msdn.microsoft.com/en-us/library/azure/jj127278.aspx
    Known SQL Data Sync Limits
    https://msdn.microsoft.com/en-us/library/azure/jj590380.aspx
    SQL Data Sync Best Practices
    https://msdn.microsoft.com/en-us/library/azure/hh667328.aspx
    Thanks,
    Lydia Zhang
    Lydia Zhang
    TechNet Community Support

  • Query for FormSubmit data by ID via the SOAP API

    When I submit a form entry via the SOAP API request 'Create' it get an ID as well as the Form Type data in return:
    <CreateResponse xmlns="https://secure.eloqua.com/API/1.2">
      <CreateResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
           <CreateResult>
                <EntityType>
                     <ID>21</ID>
                     <Name>aherghaewForm</Name>
                     <Type>Form</Type>
                </EntityType>
                <Errors/>
                <ID>3</ID>
           </CreateResult>
      </CreateResult>
    </CreateResponse>
    However, I can't seem to query for that ID. When using the request 'Query'
    <ns:Query>
      <ns:eloquaType>
           <ns:ID>21</ns:ID>
           <ns:Type>Form</ns:Type>
      </ns:eloquaType>
      <ns:searchQuery>ID='3'</ns:searchQuery>
      <ns:pageNumber>1</ns:pageNumber>
      <ns:pageSize>20</ns:pageSize>
    </ns:Query>
    I receive the following Error:
    The search query you provided is invalid: 'id' is invalid.
    As the field 'ID' is not part of the FieldValueCollection, this outcome is not unexpected, but unfortunate, as it would greatly simplify querying for data that was just submitted. Querying for a field that is part of the FieldValueCollection delivers correct results.
    Is there a way to do just that, or do i have to follow another approach to retrieve FormSubmit data?
    Thanks,
    Felix

    OK. I see column X logic now:
    SQL> select  id,
      2          name,
      3          case when instr(sys_connect_by_path(id,',') || ',',',4,') > 0 then 'X' else 'Y' end x
      4    from  worker
      5    start with id in (
      6                      select  id
      7                        from  worker
      8                        where boss_id is null
      9                        start with id = 4
    10                        connect by prior boss_id = id
    11                      )
    12    connect by prior id = boss_id
    13  /
            ID NAME                             X
             1 Mennan                           Y
             2 Ahmet                            Y
             3 Akin                             Y
             4 Ayse                             X
             5 Aylin                            X
             6 Selim                            Y
    6 rows selected.
    SQL>SY.

  • V2.1 - Exporting DATE columns produces invalid SQL

    If you export a table with a column of type DATE, the SQL produced is invalid:
    Left-click on table in tree view -> Click on "Data" tab -> Right click on data -> Export Data -> Insert -> Clipboard:
    to_timestamp('01-SEP-09 17:49:21','DD-MON-RR HH.MI.SSXFF AM')
    I have seen this work correctly, but I can't find the right combination now... but in this case the date format should be:
    to_timestamp('01-SEP-09 17:49:21','DD-MON-RR HH24.MI.SSXFF')
    Edited by: gclough on Jan 4, 2010 3:54 PM

    Hi,
    I encountered this problem since the EA and Vasan (one of the SQL Dev's team) gave the solution for this.
    >
    You can add the following in the sqldeveloper.conf to ensure that the driver doesn't report the column type of a DATE column as TIMESTAMP.
    AddVMOption -Doracle.jdbc.mapDateToTimestamp=false
    >
    As you can see on
    Re: 2.1 EA1: Problems on Date type columns
    I wonder, why this isn't included on the default installation of the product, since it is absolutely wrong to use Timestamp for Date type column on the first place.
    Regards,
    Buntoro

  • SQL query for making the horizontally stored data to vertical format

    HI i have a table named table1 and columns and data as below like below
    table1
    Main sub1 sub2 sub3 sub4 sub5 sub6
    A L1 T1
    B L1 T1
    C L2 T2 K1 T1
    D L2 T2 K1 T1
    Basically the data is stored in horizontal above.i want a query to make the data in vertical like below
    A T1
    A L1
    B T1
    B L1
    C T1
    C K1
    C T2
    C L2
    D T1
    D K1
    D T2
    D L2
    Aslo even if the values come in sub5 and sub6 the query should handle and populate the values vertically and also if a new row added also.
    Thanks a lot in advance

    Hi,
    As usual, Hoek is absolutely correct.
    There are a gazillion examples out there, but someone (I) will give you a specific answer.
    Search for "pivot" or "rows to columns" and you will indeed get a gazillion hits. Unfortunately, all but a hemi-semi-demi-gazillion of them will say "There are already lots of examples out there: do a search". Perhaps [this one|http://forums.oracle.com/forums/message.jspa?messageID=3227388#3227388] can get you started.
    The essential form of a pivot is:
    SELECT       r_val
    ,       MIN (CASE WHEN c_val = 1 THEN d END)     AS col_1
    ,       MIN (CASE WHEN c_val = 2 THEN d END)     AS col_2
    ,       MIN (CASE WHEN c_val = n THEN d END)     AS col_n
    FROM       table_x
    GROUP BY  r_val;Instead of MIN (which is probably what want) any aggregate function can be used.
    This assumes you have a column r_val that indicates what row of output will contain each value. In your example, that's your first column,
    It also assumes you have a column c_val that indicates what column will contain each value. In your example, what is that? Looking at the raw data, how can you tell that 'L2' will wind up in the 2nd column of 'D L2 T2 K1 T1', and not the 3rd, 4th or 5th? You may need to assign a c_val to each row (using the aggregate ROW_NUMBER function, perhaps).

  • Query for file version less than 10.0 does not return expected data

    I'm trying to build a query for all PCs that have a version of Iexplore.exe in c:\windows\program files\ that is less than 10.0 .  When I run the query it returns no data. When I change 10.0 in the query to 9.9 it returns files with version 10.xxx in
    the results.  Its as if it is seeing 10.0 as 1.0.   Is this expected ?
    select SMS_R_System.Name, SMS_R_System.ADSiteName, SMS_G_System_SoftwareFile.FileName, SMS_G_System_SoftwareFile.FileVersion from  SMS_R_System inner join SMS_G_System_SoftwareFile on SMS_G_System_SoftwareFile.ResourceID = SMS_R_System.ResourceId where
    SMS_G_System_SoftwareFile.FileName = "iexplore.exe" and SMS_G_System_SoftwareFile.FilePath = "C:\\program files\\internet explorer\\" and SMS_G_System_SoftwareFile.FileVersion < "9.9"

    It is because the values are not integer, they are a string. And therefore 1 is smaller then 9.
    http://www.enhansoft.com/

  • Query for an in between date

    I need to make a query that checks to see if the start_date is less than sysdate and the end_date is greater than sysdate
    SELECT * FROM table WHERE OFFICE_START_DATE < SYSDATE AND OFFICE_END_DATE > SYSDATE
    What is the easiest way of doing this?
    Thanks

    user9179751 wrote:
    It wasn't working for me initially but I had to format the date to validate.
    SELECT * FROM TABLE WHERE OFFICE_START_DATE < TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS')
    AND OFFICE_END_DATE > TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS');As skvaish said, it looks as if your columns are character (varchar2, most likely) and not dates. And if so, your solution is still buggy. You should be doing
    select *
    from mytable
    where to_date(office_start_date) < sysdate
      and  to_date(office_end_date) > sysdate;If you insist on thinking that a chracter string that looks like a date is a date, what do you make of this:
    First, create a table with a char column used as a date:
    SQL> drop table mydemo;
    Table dropped.
    SQL> create table mydemo (
      2  alfa_date varchar2(11),
      3  rite_date date
      4  );
    Table created.Now insert some data
    SQL> --
    SQL> insert into mydemo values ('01-JAN-2010', to_date('01-JAN-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('01-FEB-2010', to_date('01-FEB-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('01-APR-2010', to_date('01-APR-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('02-JAN-2010', to_date('02-JAN-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('02-FEB-2010', to_date('02-FEB-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('02-APR-2010', to_date('02-APR-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('03-JAN-2010', to_date('03-JAN-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('03-FEB-2010', to_date('03-FEB-2010','DD-MON-YYYY'));
    1 row created.
    SQL> insert into mydemo values ('03-APR-2010', to_date('03-APR-2010','DD-MON-YYYY'));
    1 row created.
    SQL> commit;
    Commit complete.Now, select, and order on the alfa-date;
    SQL> select * from mydemo order by alfa_date;
    ALFA_DATE   RITE_DATE
    01-APR-2010 01-APR-10
    01-FEB-2010 01-FEB-10
    01-JAN-2010 01-JAN-10
    02-APR-2010 02-APR-10
    02-FEB-2010 02-FEB-10
    02-JAN-2010 02-JAN-10
    03-APR-2010 03-APR-10
    03-FEB-2010 03-FEB-10
    03-JAN-2010 03-JAN-10
    9 rows selected.Are they in date sequence?
    No they are not.
    Why not?
    Now select, and order on the properly defined date column.
    SQL> select * from mydemo order by rite_date;
    ALFA_DATE   RITE_DATE
    01-JAN-2010 01-JAN-10
    02-JAN-2010 02-JAN-10
    03-JAN-2010 03-JAN-10
    01-FEB-2010 01-FEB-10
    02-FEB-2010 02-FEB-10
    03-FEB-2010 03-FEB-10
    01-APR-2010 01-APR-10
    02-APR-2010 02-APR-10
    03-APR-2010 03-APR-10
    9 rows selected.
    SQL> spo off

  • Query for data

    Hi all, i am trying to write a query for a specific scenario using analytic functions.
    i have a table that has data in week basis. here is some sample data
    id date value
    1 1/4/10 A
    1 1/11/10 B
    1 1/18/10 C
    2 ....
    2 ....
    each date represent the beginning of the week. i have another table that contains calendar dates that include day of the week excluding weekends and holidays.
    example data
    id date
    1 1/4/10
    1 1/5/10
    1 1/6/10
    1 1/7/10
    1 1/8/10
    1 1/11/10
    1 ...... SO ON
    as you can see 1/1/10, 1/2, 1/3 are not present because they are either holidays or weekends.
    what i want to do is join this two tables by id and the output should be the following
    1 1/4/10 A
    1 1/5/10 A
    1 1/6/10 A
    1 1/7/10 A
    1 1/8/10 A
    1 1/11/10 B
    1 1/12/10 B
    1 1/13/10 B
    1 1/14/10 B
    1 1/15/10 B
    and so on. so as you can see. i am converting the week table (first table) into day basis. i tried to use analytic function but i was not very successful since i am new to them. any help will be appricatiate. provide sample query if possible. thanks a lot

    Hi,
    What if the week crosses over 2 months.
    Fo example March the last week starts on 29 and has 1st apr and 2nd apr in the same week.Would you consider those?
    If not here is one way of doing it.
    with t1 as (
                select 1 id,DATE '2010-03-01' dt,'A' val from dual union all
                select 1,DATE '2010-03-08','B' from dual union all
                select 1,DATE '2010-03-15','C' from dual UNION ALL
                select 1,DATE '2010-03-22','D' from dual    UNION ALL
                select 1,DATE '2010-03-29','E' from dual  
         t2 as (
                select 1 id,DATE '2010-03-01' dt from dual union all
                select 1,DATE '2010-03-02' from dual union all
                select 1,DATE '2010-03-03' from dual union all
                select 1,DATE '2010-03-04' from dual union all
                select 1,DATE '2010-03-05' from dual union all
                select 1,DATE '2010-03-08' from dual union all
                select 1,DATE '2010-03-09' from dual union all
                select 1,DATE '2010-03-10' from dual union all
                select 1,DATE '2010-03-11' from dual union all
                select 1,DATE '2010-03-12' from dual UNION ALL
                select 1,DATE '2010-03-15' from dual UNION ALL
                select 1,DATE '2010-03-16' from dual UNION ALL           
                select 1,DATE '2010-03-17' from dual UNION ALL
                select 1,DATE '2010-03-18' from dual UNION ALL
                select 1,DATE '2010-03-19' from dual UNION ALL
                select 1,DATE '2010-03-22' from dual UNION ALL
                select 1,DATE '2010-03-23' from dual UNION ALL                                               
                select 1,DATE '2010-03-24' from dual UNION ALL                                                           
                select 1,DATE '2010-03-25' from dual UNION ALL                                                           
                select 1,DATE '2010-03-26' from dual UNION ALL                                                         
                select 1,DATE '2010-03-29' from dual UNION ALL
                select 1,DATE '2010-03-30' from dual UNION ALL
                select 1,DATE '2010-03-31' from dual UNION ALL
                select 1,DATE '2010-04-01' from dual UNION ALL  
                select 1,DATE '2010-04-01' from dual                                )
               SELECT DISTINCT a.ID,b.dt,a.val,to_char(b.dt,'IW') FROM t1 a,t2 b WHERE a.ID=b.ID
               AND to_char(a.dt,'MON')=to_char(b.dt,'MON')
               AND to_char(a.dt,'IW')=to_char(b.dt,'IW')
               ORDER BY val,dtCheers!!!
    Bhushan

  • Trouble writing Query for Pivoting data from a table

    I am having a little trouble writing a query for converting the below table data into a pivot data. I am trying to write a query for which if I give a single valid report_week date as input it should give me the data for that week and also provide two extra columns, one which gives the data of last week for the same countries and the second column which gives the difference of numbers in both the columns(i.e. COUNT - COUNT_LAST_WEEK).
    REPORT_WEEK     DIVISION     COUNT
    9/26/2009     country1     81
    9/26/2009     country2     97
    9/26/2009     country3     12
    9/26/2009     country4     26
    9/26/2009     country5     101
    10/3/2009     country1     85
    10/3/2009     country2     98
    10/3/2009     country3     10
    10/3/2009     country4     24
    10/3/2009     country5     101
    10/10/2009     country1     84
    10/10/2009     country2     98
    10/10/2009     country3     10
    10/10/2009     country4     25
    10/10/2009     country5     102
    For example, if I give input as 10/10/2009, the output should be as give below.
    REPORT_WEEK     DIVISION     COUNT     COUNT_LAST_WEEK     DIFFERENCE
    10/10/2009     country1     84     85     -1
    10/10/2009     country2     98     98     0
    10/10/2009     country3     10     10     0
    10/10/2009     country4     25     24     1
    10/10/2009     country5     102     101     1
    For example, if I give input as 10/3/2009, the output should be as give below.
    REPORT_WEEK     DIVISION     COUNT     COUNT_LAST_WEEK     DIFFERENCE
    10/3/2009     country1     85     81     4
    10/3/2009     country2     98     97     1
    10/3/2009     country3     10     12     -2
    10/3/2009     country4     24     26     -2
    10/3/2009     country5     101     101     0
    Can anyone please shed some light on Query building for the above scenarios.
    Thank you
    SKP
    Edited by: user11343284 on Oct 10, 2009 7:53 AM
    Edited by: user11343284 on Oct 10, 2009 8:28 AM

    I assume there is no gap in report weeks. If so:
    SQL> variable report_week varchar2(10)
    SQL> exec :report_week := '10/10/2009'
    PL/SQL procedure successfully completed.
    with t as (
               select to_date('9/26/2009','mm/dd/yyyy') report_week,'country1' division,81 cnt from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country2',97 from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country3',12 from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country4',26 from dual union all
               select to_date('9/26/2009','mm/dd/yyyy'),'country5',101 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country1',85 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country2',98 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country3',10 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country4',24 from dual union all
               select to_date('10/3/2009','mm/dd/yyyy'),'country5',101 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country1',84 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country2',98 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country3',10 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country4',25 from dual union all
               select to_date('10/10/2009','mm/dd/yyyy'),'country5',102 from dual
    select  max(report_week) report_week,
            division,
            max(cnt) keep(dense_rank last order by report_week) cnt_this_week,
            max(cnt) keep(dense_rank first order by report_week) cnt_last_week,
            max(cnt) keep(dense_rank last order by report_week) - max(cnt) keep(dense_rank first order by report_week) difference
      from  t
      where report_week in (to_date(:report_week,'mm/dd/yyyy'),to_date(:report_week,'mm/dd/yyyy') - 7)
      group by division
      order by division
    REPORT_WE DIVISION CNT_THIS_WEEK CNT_LAST_WEEK DIFFERENCE
    10-OCT-09 country1            84            85         -1
    10-OCT-09 country2            98            98          0
    10-OCT-09 country3            10            10          0
    10-OCT-09 country4            25            24          1
    10-OCT-09 country5           102           101          1
    SQL> exec :report_week := '10/3/2009'
    PL/SQL procedure successfully completed.
    SQL> /
    REPORT_WE DIVISION CNT_THIS_WEEK CNT_LAST_WEEK DIFFERENCE
    03-OCT-09 country1            85            81          4
    03-OCT-09 country2            98            97          1
    03-OCT-09 country3            10            12         -2
    03-OCT-09 country4            24            26         -2
    03-OCT-09 country5           101           101          0
    SQL> SY.

  • Two or more productid will be accquired by same customerid, by same shipvia, on the same day of the week of shipped date. i want the simple query for this.

    consider this situation,
     Two or more productid will be accquired by same customerid, by same shipvia, on the same  day of the week of shipped date. i want the simple query for this.
    my tables are  from northwind:
    [orders] = OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate, ShippedDate, ShipVia, Freight, ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry.
    [orders details] = OrderID, ProductID, UnitPrice, Quantity, Discount.
    i tried some but it is not exact, it gives wrong result.
    select pd.CustomerID,pd.ProductID, pd.no_of_time_purchased, sd.ShipVia, sd.same_ship_count, shipped_day from
    select ProductID,o.CustomerID,COUNT(productid) as no_of_time_purchased
    from orders o join [Order Details] od on o.OrderID=od.OrderID group by ProductID,o.CustomerID
    having count(od.ProductID) >1) pd
    join
    (select OrderID,customerid, shipvia, count(shipvia)as same_ship_count, DATENAME(DW,ShippedDate)as shipped_day from orders
    group by customerid, ShipVia, ShippedDate having COUNT(ShipVia) > 1 ) sd
    on sd.CustomerID=pd.CustomerID

    Hi,
    I think I have a solution that will at least give you a clue how to go about it. I have simplified the tables you mentioned and created them as temporary tables on my side, with some fake data to test with. I have incldued the generation of these temporary
    tables for your review.
    In my example I have included:
    1. A customer which has purchased the same product on the same day, using the same ship 3 times,
    2. Another example the same as the first but the third purchase was on a different day
    3. Another example the same as the first but the third purchase was a different product
    4. Another example the same as the first but the third purchase was using a different "ShipVia".
    You should be able to see that by grouping on all of the columns that you wich to return, you should not need to perform any subselects.
    Please let me know if I have missed any requirements.
    Hope this helps:
    CREATE TABLE #ORDERS
     OrderID INT,
     CustomerID INT,
     OrderDate DATETIME,
     ShipVia VARCHAR(5)
    CREATE TABLE #ORDERS_DETAILS
     OrderID INT,
     ProductID INT,
    INSERT INTO #ORDERS
    VALUES
    (1, 1, GETDATE(), 'ABC'),
    (2, 1, GETDATE(), 'ABC'),
    (3, 1, GETDATE(), 'ABC'),
    (4, 2, GETDATE() - 4, 'DEF'),
    (5, 2, GETDATE() - 4, 'DEF'),
    (6, 2, GETDATE() - 5, 'DEF'),
    (7, 3, GETDATE() - 10, 'GHI'),
    (8, 3, GETDATE() - 10, 'GHI'),
    (9, 3, GETDATE() - 10, 'GHI'),
    (10, 4, GETDATE() - 10, 'JKL'),
    (11, 4, GETDATE() - 10, 'JKL'),
    (12, 4, GETDATE() - 10, 'MNO')
    INSERT INTO #ORDERS_DETAILS
    VALUES
    (1, 1),
    (2, 1),
    (3, 1),
    (4, 2),
    (5, 2),
    (6, 2),
    (7, 3),
    (8, 3),
    (9, 4),
    (10, 5),
    (11, 5),
    (12, 5)
    SELECT * FROM #ORDERS
    SELECT * FROM #ORDERS_DETAILS
    SELECT
     O.CustomerID,
     OD.ProductID,
     O.ShipVia,
     COUNT(O.ShipVia),
     DATENAME(DW, O.OrderDate) AS [Shipped Day]
    FROM #ORDERS O
    JOIN #ORDERS_DETAILS OD ON O.orderID = OD.OrderID
    GROUP BY OD.ProductID, O.CustomerID, O.ShipVia, DATENAME(DW, O.OrderDate) HAVING COUNT(OD.ProductID) > 1
    DROP TABLE #ORDERS
    DROP TABLE #ORDERS_DETAILS

  • Crosstab Query for Remaining Revenue (Count, If, Date Between )

    Hi all, hope you had a great new year.
    I am wanting to create a crosstab query for my Projects which shows ProjectID in the row headers and Time Periods split into months quarter or year as the Column Headers using the [DateAgreed] from the Session table. 
    I have created crosstabs which show revenue from sessions and count of sessions with different time periods but i am trying to make it so that it counts only completed sessions from before the column date, so that i can then multiply by the [SessionCost].
    Any ideas guys?
    Here's what i have been working with;
    TRANSFORM Sum(([tblSession]![SessionCompleted]*[tblProject]![SessionCost])) AS Revenue
    SELECT tblProject.ProjectID, tblCompany.CompanyName
    FROM (tblSession INNER JOIN tblCompany ON tblSession.CompanyID = tblCompany.CompanyID) INNER JOIN ((tblProject INNER JOIN tblProjectMetrics ON tblProject.ProjectID = tblProjectMetrics.ProjectID) INNER JOIN qryProjectStatus ON tblProject.ProjectID = qryProjectStatus.ProjectID)
    ON (tblProject.ProjectID = tblSession.ProjectID) AND (tblCompany.CompanyID = tblProject.CompanyID)
    GROUP BY tblProject.ProjectID, tblCompany.CompanyName, tblProject.Total
    PIVOT Format([DateAgreed],"yyyy-mm");
    Thanks :)

    Hi Gord0oo,
    You could concatenates the data as a result and show in a cell.
    TRANSFORM Sum([tblProject]![SessionCost])) & ";" & Sum([tblSession]![SessionCompleted]) AS Revenue
    Regards
    Starain
    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.

Maybe you are looking for

  • Table maintenance generator is not saving entries.

    Hi All, I am facing problem in table maintenance generator. I created a table maintenance for Z-Table. In my table last 2 fields are a checkbox. When we go to Sm30 and check/uncheck the boxes then save , message comes tht data saved , but when we com

  • Does anyone know who and how i can talk to someone about my itunes billing?

    im trying to find out why im getting billied for something i didnt purchase....

  • 10.4.6 Software Update Has Speeded Things Up!

    I did the software update this morning on my iBook G4. I didn't try the combo. I'm wondering if we should always update using combo to prevent potential problems. I did permissions after also. I have noticed a definite performance boost. I checked mo

  • Sounds missing

    The problem I ran into is that when I try to load an instrument (nothing particularly) Logic just can't find the sound files needed to open the instrument.It happened so with some Garageband songs as well which I wanted to open in Logic but some inst

  • "Getting started"  for connectivity to OAM from OSB

    I am completely new to OAM IdXml. I need to do POC to make connectivity to OAM for CRUD operations from OSB. Where can I start from? Is there any "Getting started" Guide or Any beginer steps to follow to get started?