Need help writing a query for following scenario

Hi all, I need some help writing a query for the following case:
One Table : My_Table
Row Count: App 5000
Columns of Interest: AA and BB
Scenario: AA contains some names of which BB contains the corresponding ID. Some
names are appearing more than once with different IDs. For example,
AA BB
Dummy 10
Me 20
Me 30
Me 40
You 70
Me 50
Output needed: I need to write a query that will display only all the repeating names with their corresponding IDs excluding all other records.
I would appreciate any input. Thanks

Is it possible to have a records with the same values for AA and BB? Are you interested in these rows or do you only care about rows with the same value of AA and different BB?
With a slight modification of a previous posting you can only select those rows that have distinct values of BB for the same value of AA
WITH t AS (
SELECT 'me' aa, 10 bb FROM dual
UNION ALL
SELECT 'me' aa, 20 bb FROM dual
UNION ALL
SELECT 'you' aa, 30 bb FROM dual
UNION ALL
SELECT 'you' aa, 30 bb FROM dual
SELECT DISTINCT aa, bb
  FROM (SELECT aa, bb, COUNT(DISTINCT bb) OVER(PARTITION BY aa) cnt FROM t)
WHERE cnt > 1;

Similar Messages

  • Need help writing sql query

    i am trying to write sql query for a single recordset.
    I have an items table with all the standard item info and an item_colorID.
    i have a color_lookup table with 2 columns, item_colorID and color_ID
    i have a colors table with 2 columns, color_ID and color
    i want to join the tables and filter it so that a repeat region shows dynamic data of item name, description, thumb, price
    and also a list/menu dynamically populated by color
    filtered so that each item shows in the list/menu only the colors that the item has available.
    i have tried different variations of this sql
    SELECT * FROM items INNER JOIN color_lookup ON color_lookup.item_colorID = items.item_colorID INNER JOIN colors ON colors.color_ID = color_lookup.color_ID WHERE items.itemCatID = 3 ORDER BY items.itemName
    but the list/menu shows every color choice multiplied by the number of items in that color
    ie  White will show 80+ times.
    thanks for your help,
    jim balthrop

    bregent,
    thanks for your help.
    I am building a shopping cart and i have a recordset to list the items and a repeat region for that recordset
    i have a second recordset for the colors joined to the item_colorID nested inside the repeat region.
    the shopping cart software has a 'lookup from recordset' choice for the add to cart servior behavior
    and then i bind to the columns on the cart page.
    it produces this code
    if (isset($totalRows_rs_itemscat3) && $totalRows_rs_itemscat3 > 0)    {
        $row_rs_itemscat3 = WAEC_findRecordMySQL($rs_itemscat3, "item_ID", $ATC_itemID);
        if ($row_rs_itemscat3)    {
          $ATC_itemName = "".$row_rs_itemscat3['itemName']  ."";// column binding
          $ATC_itemDescription = "".$row_rs_itemscat3['itemShortDesc']  ."";// column binding
          $ATC_itemWeight = floatval("".$row_rs_itemscat3['itemWeight']  ."");// column binding
          $ATC_itemQuantity = "".$_POST["Farrington_1_Quantity_Add"]  ."";// column binding
          $ATC_itemPrice = floatval("".$row_rs_itemscat3['itemPrice']  ."");// column binding
          $ATC_itemThumbnail = "".$row_rs_itemscat3['itemThumb']  ."";// column binding
          $ATC_itemcolorchoice = "".$row_rs_colors['color']  ."";// column binding
          mysql_data_seek($rs_itemscat3, 0);
          $row_rs_itemscat3 = mysql_fetch_assoc($rs_itemscat3);
    the column binding for the colors is from a different recordset and when redirecting to the cart page the color info will not show.
    So my thinking is if i could get the color list/menu to populate from the same recordset as the item listing, it would solve my add to cart server behavior.
    Is it possible to do this with only one recordset?
    the products page and the cart page can be seen
    http://www.farrington-enterprises.com/rain-gutters.php
    add an item to the cart with any color choice and the color info does not carry to the cart.

  • Need help with named query for 1-to-many entities

    Hi all,
    I'm in desperate need of a query and I can't seem to figure it out.
    Here's the situation:
    I have 2 entities in a one-to-many relationship. One ServerInstance to Many AppUrl's related by a join table
    @Entity
    public class ServerInstance implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Integer id;
    private String instancename;
    private String description;
    private String home;
    private String hostname;
    private String hostname_front;
    private String ipfront;
    private String ipback;
    private String os;
    private String layer;
    @OneToMany (fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
    private List<AppUrl> appUrl = new ArrayList<AppUrl>();
    @Entity
    public class AppUrl implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private Integer id;
    private String appurl;
    private String description;
    private String keyword;
    private Integer priority;
    private String curlresult;
    In the underlying database they are mapped by the table T_SERVERINSTANCE_T_APPURL
    What I need is a named query in the ServerInstance entity to find any AppUrl where curlresult = 'down'
    I tried the following:
    @NamedQuery
    (name = "findDownInstances", query = "SELECT i FROM ServerInstance i WHERE i.appUrl.result = 'down')
    This gave me the following error:
    invalid navigation expression [i.appUrl.result], cannot navigate collection valued association field [appUrl].
    Is there any way to create a query which will do what I want?
    Thanx in advance!

    can you provide the equivalent SQL (not JPQL!) query that you want, based on tables T_SERVERINSTANCE and T_APPURL, so that there are no misunderstandings ?

  • Need Help with complex query for productio database

    Hello again,
    i need your help again, for an query how Shows me how long every production step takes per Order.
    See sample data and what i expect.
    Thank you all for your help.
    We use Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    Here the sample data tables:
    CREATE      TABLE      TABLE_2
    (     "ORDER_NR"      VARCHAR2 (12)
    ,      "PRIORITY"      VARCHAR2 (2)
    ,      "WO_STEP"      VARCHAR2 (1)
    ,      "STEP_DATE"      DATE
    CREATE      TABLE      TABLE_1
    (     "ORDER_NR"           VARCHAR2     (12) PRIMARY KEY
    ,      "PRIORITY"           VARCHAR2      (2)
    ,      "CREATE_DATE"      DATE
    ,     "ACT_STEP"          VARCHAR2     (2)
    ,     "STEP_DATE"          DATE
    ,     "EMPLOYEE"          VARCHAR2     (5)
    ,     "DESCRIPTION"     VARCHAR2     (20)
    INSERT      INTO      TABLE_1      (ORDER_NR,               PRIORITY,      CREATE_DATE,                                                        ACT_STEP,     STEP_DATE,                                                            EMPLOYEE,     DESCRIPTION)
                        VALUES           ('1KKA1T205634',     '12',          TO_DATE('10-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'),     'U',          TO_DATE('28-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS'),     'W0010',     'CLEAN HOUSE');
    INSERT      INTO      TABLE_1      (ORDER_NR,               PRIORITY,     CREATE_DATE,                                                        ACT_STEP,     STEP_DATE,                                                            EMPLOYEE,     DESCRIPTION)
                        VALUES           ('1KKA1Z300612',     '12',          TO_DATE('08-FEB-13 14:00:00','DD-MON-RR HH24:MI:SS'),     'F',          TO_DATE('20-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'),     'K0052',     'REPAIR CAR');
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'A',          TO_DATE('12-FEB-13 13:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          '5',          TO_DATE('13-FEB-13 09:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'K',          TO_DATE('13-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          '5',          TO_DATE('13-FEB-13 11:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'K',          TO_DATE('13-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          '5',          TO_DATE('13-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'C',          TO_DATE('14-FEB-13 08:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'B',          TO_DATE('14-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'E',          TO_DATE('18-FEB-13 13:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'F',          TO_DATE('20-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'S',          TO_DATE('21-FEB-13 08:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'R',          TO_DATE('21-FEB-13 09:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'U',          TO_DATE('28-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'A',          TO_DATE('12-FEB-13 13:52:42','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          '5',          TO_DATE('13-FEB-13 09:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'K',          TO_DATE('13-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          '5',          TO_DATE('13-FEB-13 11:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'K',          TO_DATE('13-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          '5',          TO_DATE('13-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'C',          TO_DATE('14-FEB-13 08:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'B',          TO_DATE('14-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'E',          TO_DATE('18-FEB-13 13:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'F',          TO_DATE('20-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'));
    COMMIT;And here is what i expect from my query:
    SYSDATE     28.Feb.13 14:00                                                                                     
    ORDER_NR     PRIORITYCREATE_DATE     STATUS     STATUS_DATE     DESCRIPTION     AGE_1     AGE_2     WAITNG     STEP_A     STEP_B     STEP_C     STEP_5     STEP_K     STEP_E     STEP_F     STEP_S     STEP_R     
    1KKA1T205634     12     10.Feb.13 10:00     U     28.Feb.13 12:00     CLEAN HOUSE     18,083     8,833     2,125     0,833     4,125     0,083     0,750     0,208     2,125     0,666     0,042     7,125     
    1KKA1Z300612     12     08.Feb.13 14:00     F     20.Feb.13 16:00     REPAIR CAR     20,000     16,042     2,125     0,833     4,125     0,083     0,750     0,208     2,125     0,666          And now the explanation to the query result:
    The AGE_1 is the difference in days between the 'CREATE_DATE' and IF EXSIST the STEP 'U' then STEP_DATE or if the STEP 'U' is not found in TABLE_2 then it should show the difference in days between the 'CREATE_DATE' and the 'SYSDATE'
    The AGE_2 is the difference in days between the STEP 'A' STEP_DATE and IF EXSIST the STEP 'R' then STEP_DATE or if the STEP 'R' is not found in TABLE_2 then it should show the difference in days between the 'CREATE_DATE' and the 'SYSDATE'
    The WAITING is the difference in days between CREATE_DATE and STEP 'A' STEP_DATE
    The following columns show the days how long the ORDER_NR stays in these STEP, if an ORDER_NR comes into the same STEP more then one time it should be calculated together.
    If the ORDER_NR skips a step it should show a zero in the specific field.
    I hope my explanation is good enough, my english skills are far away from good.
    Thanks all for your help.
    Greets Reinhard W.

    Hi,
    i changed this query:
    with t2 as (
                select  t.*,
                        lead(step_date) over(partition by order_nr order by step_date) next_step_date
                  from  table_2 t
    select  t1.*,
            nvl(
                max(
                    case t2.wo_step
                      when 'U' then t2.step_date
                    end
               sysdate
              ) - t1.create_date age_1,
            nvl(
                max(
                    case t2.wo_step
                      when 'R' then t2.step_date
                    end
               sysdate
              ) - t1.create_date age_2,
            sum(
                case t2.wo_step
                  when 'B' then t2.next_step_date - t2.step_date
                end
               ) step_b
      from  table_1 t1,
            t2
      where t2.order_nr = t1.order_nr
      group by t1.order_nr,
               t1.priority,
               t1.create_date,
               t1.act_step,
               t1.step_date,
               t1.employee,
               t1.descriptionTo this:
    with t2 as (
                select  t.*,
                        lead(step_date) over(partition by order_nr order by step_date) next_step_date
                  from  table_2 t
    select  t1.order_nr,
            nvl(
                max(
                    case t2.wo_step
                      when 'U' then t2.step_date
                    end
               sysdate
              ) - t1.create_date age_1,
            nvl(
                max(
                    case t2.wo_step
                      when 'R' then t2.step_date
                    end
               sysdate
              ) - t1.create_date age_2,
            sum(
                case t2.wo_step
                  when 'B' then t2.next_step_date - t2.step_date
                end
               ) step_b
      from  table_1 t1,
            t2
      where t2.order_nr = t1.order_nr
      group by t1.order_nrthen i get the ORA-00979 Error.
    Whats wrong?
    I have another question.
    How can i handle i i want to group to or more 'STEP's in one Column.
    in Case of this i want that the column 'STEP_B' contains all days for STEP 'B' and STEP '5'.
    I tried already with a + Operation like this:
    with t2 as (
                select  t.*,
                        lead(step_date) over(partition by order_nr order by step_date) next_step_date
                  from  table_2 t
    select  t1.*,
            nvl(
                max(
                    case t2.wo_step
                      when 'U' then t2.step_date
                    end
               sysdate
              ) - t1.create_date age_1,
            nvl(
                max(
                    case t2.wo_step
                      when 'R' then t2.step_date
                    end
               sysdate
              ) - t1.create_date age_2,
            Round( sum(
                case t2.wo_step
                  when 'B' then t2.next_step_date - t2.step_date
                end
               ) +
            sum(
                case t2.wo_step
                  when '5' then t2.next_step_date - t2.step_date
                end
               ), 3 ) step_b
      from  table_1 t1,
            t2
      where t2.order_nr = t1.order_nr
      group by t1.order_nr,
               t1.priority,
               t1.create_date,
               t1.act_step,
               t1.step_date,
               t1.employee,
               t1.descriptionBut this does reply evertime a NULL.
    Thank You.

  • Need Help Writing a Query.

    OK, i have been trying to write a query now and have gone in several different directions and find myself stuck back at square one and was hoping someone could help me out.
    Here is my issue and i'll try to explain as best as i can.
    Example: i have the following data.
    Desc 1 --- Instruct 1 --- 2/2/2009
    Desc 1 --- Instruct 1 --- 2/7/2009
    Desc 1 --- Instruct 1 --- 2/3/2009
    Desc 1 --- Instruct 2 --- 2/5/2009
    Desc 2 --- Instruct 1 --- 2/3/2009
    Desc 2 --- Instruct 1 --- 2/1/2009
    What i need to do is write a query that will show distinct Descriptions as well as distinct instructions. (Example, Desc 1 could have 7 different instructions, so i would need 7 different lines for Desc 1, with the most recent date and a count for how many occurances of each specific instruction, for each specific Description for each of the 7 lines for Desc 1.
    Example of results would be like this
    Desc 1 --- Instruct 1 --- 2/7/2009 --- 3
    Desc 1 --- Instruct 2 --- 2/5/2009 --- 1
    Desc 2 --- Instruct 1 --- 2/3/2009 --- 2
    Hopefully that is enough information, but if anything else is needed for me to provide in order to get some help, just let me know and i will do my best to get that information.
    thanks in advance

    Frank Kulash wrote:
    Hi,
    SELECT    description
    ,         instruction
    ,         MAX (dt)     AS most_recent
    ,         COUNT (*)    AS total_num
    FROM      table_x
    GROUP BY  descrrption
    ,         instruction;"GROUP BY x, y" means the output will contain one row for every distinct combination iof x and y that occurs in the results.
    All the columns in the SELECT BY clause must be
    (a) in the GROUP BY clause,
    (b) aggregate functions (like MAX or COUNT), or
    (c) trivially dependant on (a) or (b) (for example: UPPER (description))Thank you;
    I think i was trying to over complicate things.
    So simple, yet so very effective
    thanks again

  • Need Help writing cfloop query

    I have a form with variables in it that is a duplicate. For
    example I have id1, id2, id3. I have a loop and query set up like
    this:
    <cfloop index="i" from="1" to="3">
    <cfquery name="insert_info" datasource="#dsn_slave#">
    INSERT INTO new_samples (email, id, od, id_min, id_max,
    cs_min, cs_max, material, durometer, quantity, units_of_measure,
    timestamp) VALUES (#email#, #id#, #od#, #id_min#, #id_max#,
    #cs_min#, #cs_max#, #material#, #durometer#, #quantity#, #measure#,
    #CreateODBCDateTime(Now())#)
    </cfquery>
    </cfloop>
    How do I set up id1 in the loop meaning how do I write it to
    use my index=i so that it will add the 3 sets of values?

    Assuming that you're form fields are required, validated,
    checked for their existence, etc., you could take the following
    approach:
    <cfloop from="1" to="3" index="i">
    <cfquery name="instForm" datasource="dsn">
    INSERT INTO new_samples (email)
    VALUES ('#FORM["email"&i]#')
    </cfquery>
    </cfloop>
    Naturally, add in the other fields...I'm too lazy to write
    the whole query :)!
    Hope this helps!
    Craig

  • Need help with sq01 query for FI data

    hello,
      i have created a simple query whihc requires document header and line item information , bkpf and bsis works for this, but another requirement is that business needs vendor and customer accounts to be displayed also .
    bsis does not have vendor and customer , bseg has this info but bseg cannot be used in query ,
    kindly assist with this , thanks in advance.

    hi,
    you'll find the required info in BSID (customers) and BSIK (vendors) tables (BSAD and BSAK for closed items).
    hope this helps
    ec

  • Need help writing a query that generates sequential tokens

    Updated example to accomodate duplicates in cacard and to change the #temp_tokentable.cccard to varchar(20).
    I am just having a block. I have a should be easy task, and have looked at it several ways, but cannot come up with some tsql that I would not be embarressed to show coworkers.
    This is a the simplistic example of what needs to get done - 
    cacard table has credit cards. need to replace all credit cards with a generated token. the token is generated by just adding 1 to the lasttokenused and then + the right(creditcard, 4). Then the token and clear credit card values are inserted into
    tokentable.
    cacard can be a rather large table (# of rows and wide) in production so need to be as efficient as possible. But it is a onetime conversion program.
    Thanks for any help
    IF OBJECT_ID('tempdb..#Temp_cacard') IS NOT NULL
    DROP TABLE #Temp_cacard
    IF OBJECT_ID('tempdb..#Temp_tokentable') IS NOT NULL
    DROP TABLE #Temp_tokentable
    IF OBJECT_ID('tempdb..#Temp_lasttokenused') IS NOT NULL
    DROP TABLE #Temp_lasttokenused
    Create table #temp_cacard (ccard numeric(19,0))
    Insert into #temp_cacard values (1234567891234567), (2344567890123456789),(3456789012345678900), (1234567891234567)
    Create table #temp_tokentable (token varchar(20), ccard varchar(20))
    Create table #temp_lasttokenused (token varchar(20))
    Insert into #temp_lasttokenused values ('081111111111111111')
    want to end up with
    CACARD
    08111111111111124567
    08111111111111136789
    0811111111111114890008111111111111124567
    tokentable
    08111111111111124567 1234567891234567
    08111111111111136789 2344567890123456789
    08111111111111148900 3456789012345678900
    lasttokenused
    0811111111111114

    Thought that I would post the code that reads a credit card number file and replaces card numbers
    with token values. The tokens keep the last 4 of the original credit card number. I have two example card number tables. One table -cacardn - has a numeric(19,0) card number and the other - cacardv - has a varchar(20) card
    number. My shop has credit card numbers defined as both. Obviously, another step after this runs is to encrypt the #token.data column.
    IF OBJECT_ID('tempdb..#cacardn')IS NOT NULL
    DROP TABLE #cacardn;
    IF OBJECT_ID('tempdb..#cacardv')IS NOT NULL
    DROP TABLE #cacardv;
    IF OBJECT_ID('tempdb..#Token')IS NOT NULL
    DROP TABLE #Token;
    IF OBJECT_ID('tempdb..#Temp_Token')IS NOT NULL
    DROP TABLE #Temp_Token;
    IF OBJECT_ID('tempdb..#LastToken')IS NOT NULL
    DROP TABLE #LastToken;
    -- cardnumber table that has numeric (19,0) card numbers
    Create Table #cacardn ([cccard] numeric(19,0))
    INSERT INTO #cacardn ([cccard]) VALUES
    (NULL),
    (0),
    (1111),
    (91111111111121112),
    (1111),
    (1113),
    (91111111111201120);
    -- carnumber table that has varchar(20) card numbers
    Create Table #cacardv ([cccard] varchar(20))
    INSERT INTO #cacardv ([cccard]) VALUES
    (NULL),
    ('0'),
    ('00000000000000001111'),
    ('00091111111111121112'),
    ('00000000000000001111'),
    ('00000000000000001113'),
    ('00091111111111201120');
    -- token table that has tokens, varbinary card numbers, data type (13-20) are card numbers
    Create Table #Token (
    [token] varchar(20),
    [data] varbinary(256),
    [type] int)
    INSERT INTO #Token ([token],[data],[type]) VALUES
    ('00000000000000000000', CAST('00000000000000000000' as varbinary), 13),
    ('', CAST('' as varbinary), 13),
    ('0', CAST('0' as varbinary), 13),
    ('00091111111111111111', CAST('00000000000000001111' as varbinary), 13),
    ('00091111111111121112', CAST('00000000000000001112' as varbinary), 14),
    ('00091111111111201120', CAST('00000000000000001120' as varbinary), 20)
    -- Temporary, Intermediate table
    CREATE TABLE #Temp_Token(ClearValue varchar(128));
    SELECT * INTO #LastToken from (
    SELECT '0009111111111150') d (lastgeneratedToken)
    -- Create an entry in the Temp_Token table for entries in the card number field that do not match the Token table token or
    -- Token table data values. These must be card number clear values.
    -- ++ change from #cacardv to #cacardv to test both numeric and varchar card numbers
    -- ++ the card number field must not NULL, not = 0 and numberic values
    INSERT INTO #Temp_Token
    SELECT DISTINCT cccard
    FROM #cacardv l
    WHERE cccard IS NOT NULL and CAST(cccard as varchar) <> '0' and CAST(cccard as varchar) not like '%[^0-9]%' and
    NOT EXISTS (SELECT 1 FROM #Token s
    WHERE (right('00000000000000000000'+ rtrim(cccard), 20) = [token] or
    CAST(right('00000000000000000000'+ rtrim(cccard), 20) as varchar) = CAST([data] as varchar)) and
    [type] in (13,14,15,16,20))
    DECLARE @lastgeneratedToken varchar(20) = (SELECT lastgeneratedToken from #LastToken)
    -- Update the last token used
    UPDATE ifs_EDLastTokenUsed
    SET EDToken = RIGHT('0000000000000000' + CAST(@lastgeneratedToken + CAST(@@RowCount AS numeric)AS varchar), 16);
    -- Insert into the Token table
    INSERT INTO #Token
    SELECT DISTINCT RIGHT('0000000000000000' + CAST(@lastgeneratedToken + ROW_NUMBER() OVER (ORDER BY ClearValue) AS varchar(20)) + RIGHT(ClearValue,4), 20),
    CAST(RIGHT('0000000000000000' + ClearValue, 20) as varbinary), 13
    FROM #Temp_Token
    -- Now Update the card number field that matches the Token data field with the Token token field.
    -- ++ change from #cacardv to #cacardv to test both numeric and varchar card numbers
    -- ++ Do not undate NULL, 0, or non-numeric card numbers (they are invalid values)
    UPDATE c
    SET c.cccard = s.[token]
    FROM #cacardv c inner join (SELECT DISTINCT cccard, Cast([token] as varchar) as [Token]
    FROM #cacardv l inner join #Token s
    ON RIGHT('0000000000000000' + CAST(l.cccard as varchar), 20) = CAST(s.[Data] as varchar)
    WHERE [type] in (13,14,15,16,20)) s
    on c.cccard = s.cccard
    WHERE c.cccard IS NOT NULL and CAST(c.cccard as varchar) <> '0' and CAST(c.cccard as varchar) not like '%[^0-9]%'
    -- Check the Results
    select * from #cacardv
    Any comments or suggestions would be appreciated. (this is not the exact code. but the main statements are represented.)
    Wonder about my WHERE clauses that seek to exclude junk data (IS NOT NULL, <> '0', and numeric only data), shhould the WHERE close be on the inner or outer WHERE?

  • Need help writing startupItem/launchd for dansguardian

    Hey there,
    i want to write a startupitem for dansguardian (or should i use launchd?).
    i am quite new to this stuff, but thinking positive! the problem is i don't really know which file exactly starts dansguardian. there is a unix-executable in usr/local/sbin/dansguardian which i can use to start dansguardian through
    sudo /usr/local/sbin/dansguardian
    in terminal. without sudo it won't work, i then get a message saying
    vierstein$ /opt/local/sbin/dansguardian; exit
    Unable to setgid()
    logout
    i can manage dansguardian through a webinterface called webmin and i can easily start and stop it there through a link.
    i did not figure out yet how the dansguardian webmin module starts/stops it and which files/commands it uses to do that..
    how can i write a startup script for dansguardian, because doing it manually is a bit laborious. i am a bit desperate here, have been trying so many things during the last two days and i'm really stuck. hopefully somebody here knows a way to do this.
    the following code I put in a file called DansGuardian in /Library/StartupItems/Dansguardian - the file is a unix-executable
    #! /bin/sh
    # DansGuardian Filter
    . /etc/rc.common
    StartService ()
    if [ "${DGSQUID:=-NO-}" = "-YES-" ]; then
    CheckForNetwork
    if [ "${NETWORKUP}" = "-NO-" ]; then exit; fi
    ConsoleMessage "Starting DansGuardian Content Filter"
    /usr/local/sbin/dansguardian -s
    fi
    StopService ()
    /usr/local/sbin/dansguardian -q
    RestartService ()
    /usr/local/sbin/dansguardian -r
    RunService "$1"
    my StartupParameters.plist file in the same folder says
    Description = "DansGuardian Content Filter";
    Provides = ("Content Filter");
    Requires = ("Web Proxy");
    OrderPreference = "None";
    after rebooting i get this in console
    SystemStarter[55]: The following StartupItems were not attempted due to failure of a required service:
    SystemStarter[55]: /Library/StartupItems/DansGuardian
    it would be great if somebody here knew how to do this right

    in case somebody else is looking for an answer on this, here is the working launchd script. i did not write it myself though..
    put the following code in
    /Library/LaunchDaemons/org.dansguardian.dansguardian.plist
    change the "Program" string to point to your binary, and the "WatchPaths" as well. The way this one works is that it waits until Squid is launched before it starts. That's what the WatchPath does - it looks for Squid's PID file to be created, and then launches DansGuardian.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>Label</key>
    <string>org.dansguardian.dansguardian</string>
    <key>Disabled</key>
    <false/>
    <key>UserName</key>
    <string>root</string>
    <key>GroupName</key>
    <string>nogroup</string>
    <key>Program</key>
    <string>/opt/dansguardian/sbin/dansguardian</string>
    <key>ProgramArguments</key>
    <array>
    <string>dansguardian</string>
    <string>-N</string>
    </array>
    <key>RunAtLoad</key>
    <false/>
    <key>OnDemand</key>
    <false/>
    <key>WatchPaths</key>
    <array>
    <string>/opt/squid/var/logs/squid.pid</string>
    </array>
    <key>Umask</key>
    <integer>027</integer>
    <key>ServiceDescription</key>
    <string>The DansGuardian Content Filter Daemon</string>
    </dict>
    </plist>

  • Need help writing a code for this program

    Design a code that reads a sentence and prints each individual word on a different line

    tsith's suggestion is excellent. Run it and see what happens. I just did that myself and doing so I learned something new about the Scanner class.
    Before you run it, add a couple of extra System.out.println for (hopefully) illustrating debugging purposes:
    import java.lang.String;
    import java.util.Scanner;
    public class Sentence {
        // main line of program
        public static void main(String[] args) {
            boolean z;
            String a;
            Scanner keyboard = new Scanner(System.in);
            System.out.print("Enter sentence: ");
            z = keyboard.hasNext();
            while (z) {
                System.out.println("z = " + z + ". Fetching the next word...");
                a = keyboard.next();
                System.out.println(a);
            System.out.println("Done!");
    }Let us know if the program ever prints "Done!" to the console. While you are waiting, read what the javadocs has to say about the Scanner class, and pay extra attention to what it says about the hasNext() and next() methods:
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html

  • Need help writing correct code for nested button

    This is the code on the main timeline.
    stop();
    garage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
    function mouseDownHandler(event:MouseEvent):void {
        gotoAndPlay("open");
    The movieClip gDoor is nested inside of garage and "open" is a label on that timeline.  I know the gotoAndPlay("open"); isn't correct.  How would i target the label on the nested timeline.
    the link below is to dowload the fla
    clienttestsite.x10.mx/beta/garage.fla

    The problem is that you have an event listener assigned to the garage, which is blocking/overriding interaction with anything inside of it.  When you click on the chest's button, you are still clicking on the garage, which does the gotoAndPlay("open")... where it stops at the stop();
    One way to get around this is to assign an instance name to the door and assign the opening code to that....
    stop();
    garage.door.addEventListener(MouseEvent.CLICK, openHandler);
    function openHandler(event:MouseEvent):void{
       garage.play();
    garage.chest.closeBtn.addEventListener(MouseEvent.CLICK, closeHandler);
    function closeHandler(event:MouseEvent):void{
       garage.gotoAndPlay("close");
    Notes: as shown in the code above...
    - use CLICK instead of MOUSE_DOWN.
    - in the openHandler use play() instead of gotoAndPlay("open"). You are already in the "open" frame, and it is only because the stop() is used up that it actuallys works.
    Doing what I explain above also makes it so that you can click the door to close things as well.

  • Required Help and Documentations for following Scenarios. URGENT

    Hi every one,
    I require help and materials for following scenarios:
    <b>1) RFC to IDOC
    2) JDBC to RFC & IDOC
    3) Mail to File
    4) HTTP to RFC, JDBC & IDOC
    5)WEB SERVICES to RFC & IDOC
    6) IDOC to ABAP proxy
    7) Java Proxy to JDBC</b>
    my email id: <u>[email protected]</u>
    urgent plzz  help me...
    Message was edited by:
            satish c

    Satish,
    I would suggest to go through sravyas weblogs where she has given all the links to all the scenarios:
    /people/sravya.talanki2/blog/2006/12/25/aspirant-to-learn-sap-xiyou-won-the-jackpot-if-you-read-this-part-i
    /people/sravya.talanki2/blog/2006/12/26/aspirant-to-learn-sap-xiyou-won-the-jackpot-if-you-read-this-part-ii
    /people/sravya.talanki2/blog/2006/12/27/aspirant-to-learn-sap-xiyou-won-the-jackpot-if-you-read-this-part-iii
    Also check this weblogs which they have explained with some scenarios:
    Following are the links to weblogs which will help to develop the basic scenarios.
    /people/prateek.shah/blog/2005/06/08/introduction-to-idoc-xi-file-scenario-and-complete-walk-through-for-starters - IDoc to File
    /people/ravikumar.allampallam/blog/2005/03/14/abap-proxies-in-xiclient-proxy - ABAP Proxy to File
    /people/sap.user72/blog/2005/06/01/file-to-jdbc-adapter-using-sap-xi-30 - File to JDBC
    /people/prateek.shah/blog/2005/06/14/file-to-r3-via-abap-proxy - File to ABAP Proxy
    /people/venkat.donela/blog/2005/03/02/introduction-to-simplefile-xi-filescenario-and-complete-walk-through-for-starterspart1 - File to File Part 1
    /people/venkat.donela/blog/2005/03/03/introduction-to-simple-file-xi-filescenario-and-complete-walk-through-for-starterspart2 - File to File Part 2
    /people/ravikumar.allampallam/blog/2005/06/24/convert-any-flat-file-to-any-idoc-java-mapping - Any flat file to any Idoc
    /people/arpit.seth/blog/2005/06/27/rfc-scenario-using-bpm--starter-kit - File to RFC
    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/1685 [original link is broken] [original link is broken] [original link is broken] [original link is broken] - File to Mail
    /people/jayakrishnan.nair/blog/2005/06/20/dynamic-file-name-using-xi-30-sp12-part--i - Dynamic File Name Part 1
    /people/jayakrishnan.nair/blog/2005/06/28/dynamic-file-namexslt-mapping-with-java-enhancement-using-xi-30-sp12-part-ii - Dynamic File Name Part 2
    /people/michal.krawczyk2/blog/2005/03/07/mail-adapter-xi--how-to-implement-dynamic-mail-address - Dynamic Mail Address
    /people/siva.maranani/blog/2005/05/25/understanding-message-flow-in-xi - Message Flow in XI
    /people/krishna.moorthyp/blog/2005/06/09/walkthrough-with-bpm - Walk through BPM
    /people/siva.maranani/blog/2005/05/22/schedule-your-bpm - Schedule BPM
    /people/sriram.vasudevan3/blog/2005/01/11/demonstrating-use-of-synchronous-asynchronous-bridge-to-integrate-synchronous-and-asynchronous-systems-using-ccbpm-in-sap-xi - Use of Synch - Asynch bridge in ccBPM
    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/1403 [original link is broken] [original link is broken] [original link is broken] [original link is broken] - Use of Synch - Asynch bridge in ccBPM
    /people/michal.krawczyk2/blog/2005/08/22/xi-maintain-rfc-destinations-centrally - Maintain RFC destination centrally
    /people/sravya.talanki2/blog/2005/08/18/triggering-e-mails-to-shared-folders-of-sap-is-u - Triggering Email from folder
    /people/sravya.talanki2/blog/2005/08/17/outbound-idocs--work-around-using-party - Handling different partners for IDoc
    /people/siva.maranani/blog/2005/08/27/modeling-integration-scenario146s-in-xi - Modeling Integration Scenario in XI
    /people/michal.krawczyk2/blog/2005/08/25/xi-sending-a-message-without-the-use-of-an-adapter-not-possible - Testing of integration process
    /people/michal.krawczyk2/blog/2005/05/25/xi-how-to-add-authorizations-to-repository-objects - Authorization in XI
    http://help.sap.com/saphelp_nw04/helpdata/en/58/d22940cbf2195de10000000a1550b0/content.htm - Authorization in XI
    /people/michal.krawczyk2/blog/2005/09/09/xi-alerts--step-by-step - Alert Configuration
    /people/michal.krawczyk2/blog/2005/09/09/xi-alerts--troubleshooting-guide - Trouble shoot alert config
    /people/sameer.shadab/blog/2005/09/21/executing-unix-shell-script-using-operating-system-command-in-xi - Call UNIX Shell Script
    /people/sravya.talanki2/blog/2005/11/02/overview-of-transition-from-dev-to-qa-in-xi - Transport in XI
    /people/r.eijpe/blog/2005/11/04/using-abap-xslt-extensions-for-xi-mapping - Using ABAP XSLT Extensions for XI Mapping
    /people/prasad.ulagappan2/blog/2005/06/07/mail-adapter-scenarios-150-sap-exchange-infrastructure - Mail Adaptor options
    /people/pooja.pandey/blog/2005/07/27/idocs-multiple-types-collection-in-bpm - Collection of IDoc to Single File
    /people/sap.user72/blog/2005/11/17/xi-controlling-access-to-sensitive-interfaces - Controlling access to Sensitive Interfaces
    /people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14 - The same filename from a sender to a receiver file adapter - SP14
    /people/prasad.illapani/blog/2005/11/14/payload-based-message-search-in-xi30-using-trex-engine - Payload Based Message Search in XI30 using Trex Engine /people/sap.user72/blog/2005/11/24/xi-configuring-ccms-monitoring-for-xi-part-i - XI : Configuring CCMS Monitoring for XI- Part I
    /people/michal.krawczyk2/blog/2005/11/23/xi-html-e-mails-from-the-receiver-mail-adapter - XI: HTML e-mails from the receiver mail adapter
    /people/sap.user72/blog/2005/11/22/xi-faqs-provided-by-sap-updated - XI : FAQ's Provided by SAP
    Regards,
    ---Satish

  • Need to write a query for extractions

    How can I extract the following data from Oracle:
    1. Segment1 and description from mtl_system_items_b
    2. Onhand quantity that is orderable (Not under the WIP manufacturing or PO)
    3. Onhand quantity that not orderable (That is under WIP manufacturing or PO)
    4. Retail Price of these items.
    There is only one organization_id =21 needs to be considered. This extract needs to be a daily kind of an extract. If you can help me in writing the query for all the fields above with proper joins, I'll really appreciate.
    Thanks & Regards
    KM

    Hi,
    Primary_uom_code and Primary_transaction_quantity shows the items quantity on the basis of primary code
    whereas Secondary_uom_code and secondary_transction_quantity shows the items quantity on different code.
    e.g. suppose you have an item Pen opened on the primary code as Each. 1 Each = 1 Pen.
    You have a conversion set as 10 Each = 1 Pkt.
    At the time of transaction if you selects as 1 Pkt,
    The primary_transaction_quantity will show 10 Each where as the secondary_transaction_quantity will show 1Pkt.
    Now as the transaction has done as Pkt the column Transaction_quantity will display 10Pkt.
    If you have done this transaction on the primary code as 10 Each.
    The primary_transaction_quantity would show the same 10 Each but the Secondary_transaction_quantity will by
    null and the transaction_quantity will be 10 Each.
    Hope this will clarify the issue.
    2) why you want to join these tables
    How can I join the following tables: qp_list_lines and mtl_system_items_b? I want to find the price of each
    item. I tried using inventory_item_id but it does not work as inventory_item_id can be null in qp_list_lines table.i have not been able to find any thing in table qp_list_lines.

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
    The query should return the following data set
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

  • Need Help on below Query.

    Hi All,
    Need Help on below Query.
    Consider,
    "test9" Table Data in COLUMN "Name" AS
    Name
    =====
    'a'
    'b'
    'c'
    'd'
    'e'
    I am writing a query as :
    SELECT * FROM test9 WHERE Name IN ('a','b','c','d','e','f','g')
    I want result set as , It should show data as -
    'f'
    'g'
    i.e. data which does not exists in the table and which is give in in clause
    Is it possible in a single query.

    You can put the data that is to be checked for into a table instead or an inline view, for example:
    with t as
    (select 'a' as c1 from dual
    union all
    select 'b' from dual
    union all
    select 'c' from dual
    union all
    select 'd' from dual
    union all
    select 'e' from dual)
    select c1 from (select 'a' as c1 from dual
    union all
    select 'b' from dual
    union all
    select 'c' from dual
    union all
    select 'd' from dual
    union all
    select 'e' from dual
    union all
    select 'f' from dual
    union all
    select 'g' from dual)
    minus
    select c1 from t
    C
    f
    g
    2 rows selected.

Maybe you are looking for