Best way to write this sql ?

Please let me know best way to write this SQL.
select col1, count(*)
from TableA
group by col1
having count(*) =
(select max(vals)
from
select col1, count(*) as vals
from TableA
group by col1
having count(*) > 1
)

post EXPLAIN PLAN
SELECT col1,
       COUNT(*)
FROM   tablea
GROUP  BY col1
HAVING COUNT(*) = (SELECT MAX(vals)
                   FROM   (SELECT col1,
                                  COUNT(*) AS vals
                           FROM   tablea
                           GROUP  BY col1
                           HAVING COUNT(*) > 1))

Similar Messages

  • Best way to write Pl/Sql

    Dear all,
    Can someone say the best way writing below stored proc:
    procedure missing_authorized_services is
    v_truncate_sql varchar2(200);
    v_sql varchar2(2000);
    BEGIN
    v_truncate_sql := 'truncate table missing_authorized_services';
         execute immediate v_truncate_sql;
         commit;
    v_sql := 'INSERT into missing_authorized_services select distinct trim(service_group_Cd) as service_group_Cd, trim(service_cd) as service_cd from stage_1_mg_service_request
    where (service_group_cd, service_cd) not in (
                        select distinct service_group_cd, service_cd from stage_3_servcd_servgrp_dim)';
    execute immediate v_sql;
         commit;
    END missing_authorized_services;
    /* I am doing select from table and then try to Insert into a different table the result set */
    Please guide,
    Thanks
    J

    Hi,
    The best way to write PL/SQL (or any code) is in very small increments.
    Start with a very simple procedure that does something (anything), just enough to test that it's working.
    Add lots of ouput statments so you can see what the procedure is doing. Remember to remove them after testing is finished.
    For example:
    CREATE OR REPLACE procedure missing_authorized_services IS
            v_truncate_sql  VARCHAR2 (200);
    BEGIN
         v_truncate_sql := 'truncate table missing_authorized_services';
         dbms_output.put_line (  v_truncate_sql
                        || ' = v_truncate_sql inside missing_authorized_services'
    END      missing_authorized_services;If you get any errors (for example, ORA-00955, becuase you're trying to give the same name to a procedure that you're already using for a table), then fix the error and try again.
    When it worls perfectly, then add another baby step. For example, you might add the one line
    EXECUTE IMMEDIATE v_truncate_sql;and test again.
    Don't use dynamic SQL (EXECUTE IMMEDIATE) unless you have to.
    Is there any reason to use dynamic SQL for the INSERT?

  • Is this the best way to write this in AS3

    I have converted my old AS2 to As3. It now appears to work the same as before but being new to AS3 I have a few questions.
    In this example I click on a button which takes me to a keyframe that plays a MC. There is another btn that takes me back to the original page.
    In AS2 it is written like this.
    // Go to keyFrame btn
    on (release) {
    //Movieclip GotoAndStop Behavior
    this.gotoAndStop("Jpn_Scul_mc");
    //End Behavior
    // Play Movie
    on (release) {
    //Movieclip GotoAndStop Behavior
    this.gotoAndStop("Jpn_Movie");
    //End Behavior
    //load Movie Behavior
    if(this.mcContentHolder == Number(this.mcContentHolder)){
    loadMovieNum("PL_Japan_Scul.swf",this.mcContentHolder);
    } else {
    this.mcContentHolder.loadMovie("PL_Japan_Scul.swf");
    //End Behavior
    // Return key
    on (release) {
    //Movieclip GotoAndStop Behavior
    this.gotoAndStop("Jpn_Intro");
    //End Behavior
    In AS3 it is written like this.
    // Play Movie
    var myrequest_Jpn:URLRequest=new URLRequest("PL_Japan_Scul.swf");
    var myloader_Jpn:Loader=new Loader();
    myloader_Jpn.load(myrequest_Jpn);
    function movieLoaded_Jpn(myevent_Jpn:Event):void {
    stage.addChild(myloader_Jpn);
    var mycontent:MovieClip=myevent_Jpn.target.content;
    mycontent.x=20;
    mycontent.y=20;
    //unload method - Return to keyframe
    function Rtn_Jpn_Intro_(e:Event):void {
    gotoAndStop("Japan_Intro");
    Rtn_Jpn_Intro_btn.addEventListener(MouseEvent.CLICK, removeMovie_Jpn);
    function removeMovie_Jpn(myevent_Jpn:MouseEvent):void {
    myloader_Jpn.unload();
    myloader_Jpn.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded_Jpn);
    Rtn_Jpn_Intro_btn.addEventListener("click",Rtn_Jpn_Intro_);
    // Go to keyFrame btn
    function Scul_Play(e:Event):void {
    gotoAndStop("Jpn_Scul_mc");
    Jpn_Scul_btn.addEventListener("click",Scul_Play);
    1. Is there a better, more efficient way to achieve this in AS3?
    2. I have used an //unload method in the AS3 script which does remove the MC from the scene but I notice in the output tab my variable code is still being counted for the last MC played.
    Is this normal?

    Hi Andrei, I have started a new project and taken your advice to construct it with a different architecture with all the code in one place.
    I have two questions regarding your last code update.
    var myrequest_Jpn:URLRequest;
    var myloader_Jpn:Loader;
    Rtn_Jpn_Intro_btn.addEventListener(MouseEvent.CLICK, removeMovie_Jpn);
    Jpn_Scul_btn.addEventListener(MouseEvent.CLICK, Scul_Play);
    function Scul_Play(e:MouseEvent):void {
         myrequest_Jpn = new URLRequest("PL_Japan_Scul.swf");
         myloader_Jpn = new Loader();
         myloader_Jpn.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded_Jpn);
         myloader_Jpn.load(myrequest_Jpn);
    function movieLoaded_Jpn(e:Event):void {
         // remove listener
         myevent_Jpn.target.removeEventListener(Event.COMPLETE, movieLoaded_Jpn);
         this.addChild(myloader_Jpn);
         myloader_Jpn.x = 20;
         myloader_Jpn.y = 20;
         // remove objects that are in "Japan_Intro" frame
    function removeMovie_Jpn(e:MouseEvent):void {
         // add back objects that are in "Japan_Intro" frame
         // remove from display list
         this.removeChild(myloader_Jpn);
         myloader_Jpn.unload();
         myloader_Jpn = null;
         // this moved from Rtn_Jpn_Intro_ function
         //gotoAndStop("Japan_Intro");
    Its all works great except for the line to remove event..
    1.
    myevent_Jpn.target.removeEventListener(Event.COMPLETE, movieLoaded_Jpn);
    I get an error:   1120: Access of undefined property myevent_Jpn.
    Removing this statement allows the code to work but that is not a solution.
    2.
    Rtn_Jpn_Intro_btn.addEventListener(MouseEvent.CLICK, removeMovie_Jpn);
    I would like this button to remove more than one movie. Is this possible.
    Thanks for the help todate.

  • Looking for a better way to write this SQL

    Oracle version 11R2
    OS version (does not matter)
    What I trying to do is write a query that finds Public Synonyms without a target object. I came up with this but I thinking there's a better way.
    Select
      s.owner, s.synonym_name, s.table_name, s.table_owner, s.db_link, InitCap(o.object_type) object_type
    from  
      sys.DBA_SYNONYMS s, sys.DBA_OBJECTS o
    where 
      s.synonym_name is not null
    and   
      s.table_owner = o.owner (+)
    and   
      s.table_name = o.object_name (+)
    and   
      s.owner = 'PUBLIC'
    and
      object_type is null;  object_type is null appears to be the weakness. It seems the check of the target object should be better.
    Feedback, comments, queries welcome.

    I'm not sure exactly what "better" means in this context (faster, easier to read, etc.) but I'd tend to use a NOT EXISTS
    SELECT s.*
      FROM dba_synonyms s
    WHERE owner = 'PUBLIC'
       AND s.db_link IS NULL
       AND NOT EXISTS (
        SELECT 1
          FROM dba_objects o
         WHERE o.owner = s.table_owner
           AND o.object_name = s.table_name )I added the DB_LINK criteria to filter out public synonyms that reference objects in remote databases which obviously don't exist in the local DBA_OBJECTS.
    Justin

  • Best way to write this report

    I hope someone can help. I am fairly new to Oracle Reports.
    I need to compile a report with totals only. The problem is I need to pull the detail data in to perform fuctions on that detail data but I don't want to display the detail data, only the bottom line numbers. Each time I try this I get numerous blank pages where the detail would be.
    What is my best option if any and where can I find information on this?

    For performance your report should be based on a single query that returns only the total amounts. If you do not need to display the details, why return them? Using multi-level functions you can write a single query to return your desired totals - and rather than having the functions inside the report, you can have them on the server, further increasing performance.
    HTH,
    Troy
    I hope someone can help. I am fairly new to Oracle Reports.
    I need to compile a report with totals only. The problem is I need to pull the detail data in to perform fuctions on that detail data but I don't want to display the detail data, only the bottom line numbers. Each time I try this I get numerous blank pages where the detail would be.
    What is my best option if any and where can I find information on this?

  • Best way to write SELECT statement

    Hi,
    I am selecting fields from one table, and need to use two fields on that table to look up additional fields in two other tables.
    I do not want to use a VIEW to do this. 
    I need to keep all records in the original selection, yet I've been told that it's not good practice to use LEFT OUTER joins.  What I really need to do is multiple LEFT OUTER joins.
    What is the best way to write this?  Please reply with actual code.
    I could use 3 internal tables, where the second 2 use "FOR ALL ENTRIES" to obtain the additional data.  But then how do I append the 2 internal tables back to the first?  I've been told it's bad practice to use nested loops as well.
    Thanks.

    Hi,
    in your case having 2 internal table to update the one internal tables.
    do the following steps:
    *get the records from tables
    sort: itab1 by key field,  "Sorting by key is very important
          itab2 by key field.  "Same key which is used for where condition is used here
    loop at itab1 into wa_tab1.
      read itab2 into wa_tab2     " This sets the sy-tabix
           with key key field = wa_tab1-key field
           binary search.
      if sy-subrc = 0.              "Does not enter the inner loop
        v_kna1_index = sy-tabix.
        loop at itab2 into wa_tab2 from v_kna1_index. "Avoiding Where clause
          if wa_tab2-keyfield <> wa_tab1-key field.  "This checks whether to exit out of loop
            exit.
          endif.
    ****** Your Actual logic within inner loop ******
       endloop. "itab2 Loop
      endif.
    endloop.  " itab1 Loop
    Refer the link also you can get idea about the Parallel Cursor - Loop Processing.
    http://wiki.sdn.sap.com/wiki/display/Snippets/CopyofABAPCodeforParallelCursor-Loop+Processing
    Regards,
    Dhina..

  • What is a best way to write SQL ?

    Sample Case
    drop table t;
    drop table b;
    create table t ( a varchar2(4), b number, c varchar2(1));
    insert into t values ('A00', 10, 'R');
    insert into t values ('A01', 11, 'R');
    insert into t values ('A02', 12, 'R');
    insert into t values ('A03', 13, 'R');
    insert into t values ('A00', 10, 'P');
    insert into t values ('A01', 11, 'P');
    insert into t values ('A02', 12, 'P');
    insert into t values ('A03', 13, 'P');
    commit;
    create table b ( j varchar(4), k varchar2(1), l varchar2(5), m number(3), n varchar2(5), o number(3));
    insert into b values ('A00', 'P', 'FIXED', 100, 'FLOAT', 60);
    insert into b values ('A01', 'P', 'FIXED', 101, 'FIXED', 30);
    insert into b values ('A02', 'R', 'FLOAT', 45, 'FLOAT', 72);
    insert into b values ('A03', 'R', 'FIXED', 55, 'FLOAT', 53);
    commit;
    10:19:13 SQL> select * from t;
    A B C
    A00 10 R
    A01 11 R
    A02 12 R
    A03 13 R
    A00 10 P
    A01 11 P
    A02 12 P
    A03 13 P
    8 rows selected.
    10:19:19 SQL> select * from b;
    J K L M N O
    A00 P FIXED 100 FLOAT 60
    A01 P FIXED 101 FIXED 30
    A02 R FLOAT 45 FLOAT 72
    A03 R FIXED 55 FLOAT 53
    1/     In table t each reference having 2 records one with P another is with R
    2/     In table b each refrence merged into single record and there are many records which are not existing in table t
    3/      both t and j tables can be joined using a = j
    4/     If from table t for a reference indicator is 'P' then if have to pick up l and m columns, if it is 'R' then I have to pick up n and o columns
    5/     I want output in following format
    A00     P     FIXED          100
    A00     R     FLOAT          60
    A01     P     FIXED          101
    A01     R     FIXED          30
    A02     P     FLOAT          72
    A02     R     FLOAT          45
    A03     P     FLOAT          53
    A03     R     FIXED          55
    6/     Above example is a sample ouput, In above example I have picked up only l,m,n,o columns, but in real example there are many columns ( around 40 ) to be selected. ( using "case when" may not be practical )
    Kindly suggest me what is a best way to write SQL ?
    thanks & regards
    pjp

    Is this?
    select b.j,t.c as k,decode(t.c,'P',l,n) as l,decode(t.c,'P',m,o) as m
    from t,b
    where t.a=b.j
    order by j,k
    J K L M
    A00 P FIXED 100
    A00 R FLOAT 60
    A01 P FIXED 101
    A01 R FIXED 30
    A02 P FLOAT 45
    A02 R FLOAT 72
    A03 P FIXED 55
    A03 R FLOAT 53
    8 rows selected.
    or is this?
    select b.j,t.c as k,decode(t.c,b.k,l,n) as l,decode(t.c,b.k,m,o) as m
    from t,b
    where t.a=b.j
    order by j,k
    J K L M
    A00 P FIXED 100
    A00 R FLOAT 60
    A01 P FIXED 101
    A01 R FIXED 30
    A02 P FLOAT 72
    A02 R FLOAT 45
    A03 P FLOAT 53
    A03 R FIXED 55
    8 rows selected.

  • Best way to spool DYNAMIC SQL query to file from PL/SQL

    Best way to spool DYNAMIC SQL query to file from PL/SQL [Package], not SqlPlus
    I'm looking for suggestions on how to create an output file (fixed width and comma delimited) from a SELECT that is dynamically built. Basically, I've got some tables that are used to define the SELECT and to describe the output format. For instance, one table has the SELECT while another is used to defined the column "formats" (e.g., Column Order, Justification, FormatMask, Default value, min length, ...). The user has an app that they can use to customize the output...which leaving the gathering of the data untouched. I'm trying to keep this formatting and/or default logic out of the actual query. This lead me into a problem.
    Example query :
    SELECT CONTRACT_ID,PV_ID,START_DATE
    FROM CONTRACT
    WHERE CONTRACT_ID = <<value>>Customization Table:
    CONTRACT_ID : 2,Numeric,Right
    PV_ID : 1,Numeric,Mask(0000)
    START_DATE : 3,Date,Mask(mm/dd/yyyy)The first value is the kicker (ColumnOrder) as well as the fact that the number of columns is dynamic. Technically, if I could use SqlPlus...then I could just use SPOOL. However, I'm not.
    So basically, I'm trying to build a generic routine that can take a SQL string execute the SELECT and map the output using data from another table to a file.
    Any suggestions?
    Thanks,
    Jason

    You could build the select statement within PL/SQL and open it using a cursor variable. You could write it to a file using the package 'UTL_FILE'. If you want to display the output using SQL*Plus, you could have an out parameter as a ref cursor.

  • Is this REALLY the easiest/best way to do this?

    I'm no SQL guru by any means, but I can get by. Here is some background.
    I am running Perfmon Data Collector Sets to collect performance counters.
    I am using Relog.exe to take the .blg files and pushing them into a database
    I am attempting to write a query that will ultimately get the information out of the database and see if I can aggregate the data a bit as well. If the last part is better off doing in Excel (where this data will ultimately end up for charting), then I will
    do that part there.
    Here is the table layouts when you import the .blg files:
    Table name: CounterData
    Columns:
    GUID
    CounterID
    RecordIndex
    CounterDateTime
    CounterValue
    FirstValueA
    FirstValueB
    SecondValueA
    SecondValueB
    MultiCount
    Table Name: CounterDetails
    CounterID
    MachineName
    ObjectName
    CounterName
    CounterType
    DefaultScale
    InstanceName
    InstanceIndex
    ParentName
    ParentObjectID
    TimeBaseA
    TimeBaseB
    I need to pull multiple sets of data out of these tables, so I built the following query:
    USE PDB
    SELECT
    CAST(LEFT(CounterDateTime, 16) as smalldatetime) AS CounterDateTime,
    REPLACE(CounterDetails.MachineName,'\\','') AS ComputerName,
    CounterDetails.ObjectName + ISNULL('(' + CounterDetails.InstanceName + ')','') + '\' + CounterDetails.CounterName AS [Counter],
    CounterData.CounterValue
    FROM CounterData
    FULL OUTER JOIN CounterDetails ON CounterData.CounterID = CounterDetails.CounterID
    FULL OUTER JOIN DisplayToID ON CounterData.GUID = DisplayToID.GUID
    WHERE CounterDetails.ObjectName = 'Processor'
    AND CounterDetails.CounterName = '% Processor Time'
    AND CounterDetails.InstanceName = '_Total'
    UNION
    SELECT
    CAST(LEFT(CounterDateTime, 16) as smalldatetime) AS CounterDateTime,
    REPLACE(CounterDetails.MachineName,'\\','') AS ComputerName,
    CounterDetails.ObjectName + ISNULL('(' + CounterDetails.InstanceName + ')','') + '\' + CounterDetails.CounterName AS [Counter],
    CounterData.CounterValue
    FROM CounterData
    FULL OUTER JOIN CounterDetails ON CounterData.CounterID = CounterDetails.CounterID
    FULL OUTER JOIN DisplayToID ON CounterData.GUID = DisplayToID.GUID
    WHERE CounterDetails.ObjectName = 'Web Service'
    AND CounterDetails.CounterName = 'Bytes Received/sec'
    AND CounterDetails.InstanceName = 'AppName'
    ORDER BY 1
    Is this REALLY the best way to do this?
    Also, trying to figure out how to build in data aggregation in 5 minute average blocks.
    Any assistance appreciated!

    Erland,
    Thanks for your response.
    The related items in the table are CounterID, in a nutshell, what I want to do is the following:
    Get the data from the CounterDetails table that holds the MachineName, CounterName, CounterType and so forth.
    CounterID MachineName ObjectName CounterName CounterType DefaultScale InstanceName InstanceIndex ParentName ParentObjectID TimeBaseA TimeBaseB
    1 \\ServerName Web Service Bytes Received/sec 272696576 -4 Carnival NULL NULL NULL 14318180 0
    2 \\ServerName Web Service Bytes Sent/sec 272696576 -4 AppName NULL NULL NULL 14318180 0
    3 \\ServerName Web Service Current Connections 65536 0 AppName NULL NULL NULL 14318180 0
    4 \\ServerName Web Service Bytes Total/sec 272696576 -4 AppName NULL NULL NULL 14318180 0
    5 \\ServerName Web Service Get Requests/sec 272696320 0 AppName NULL NULL NULL 14318180 0
    6 \\ServerName Web Service Head Requests/sec 272696320 0 AppName NULL NULL NULL 14318180 0
    7 \\ServerName Processor % Processor Time 558957824 0 _Total NULL NULL NULL 10000000 0
    8 \\ServerName PhysicalDisk Disk Reads/sec 272696320 0 _Total NULL NULL -1 14318180 0
    9 \\ServerName PhysicalDisk Disk Reads/sec 272696320 0 0 C: D: E: NULL NULL -1 14318180 0
    10 \\ServerName PhysicalDisk Disk Read Bytes/sec 272696576 -4 _Total NULL NULL -1 14318180 0
    11 \\ServerName PhysicalDisk Disk Read Bytes/sec 272696576 -4 0 C: D: E: NULL NULL -1 14318180 0
    12 \\ServerName PhysicalDisk Disk Writes/sec 272696320 0 _Total NULL NULL -1 14318180 0
    13 \\ServerName PhysicalDisk Disk Writes/sec 272696320 0 0 C: D: E: NULL NULL -1 14318180 0
    14 \\ServerName PhysicalDisk Current Disk Queue Length 65536 1 _Total NULL NULL -1 14318180 0
    15 \\ServerName PhysicalDisk Current Disk Queue Length 65536 1 0 C: D: E: NULL NULL -1 14318180 0
    16 \\ServerName PhysicalDisk % Disk Read Time 542573824 0 _Total NULL NULL -1 10000000 0
    17 \\ServerName PhysicalDisk % Disk Read Time 542573824 0 0 C: D: E: NULL NULL -1 10000000 0
    18 \\ServerName PhysicalDisk Disk Write Bytes/sec 272696576 -4 _Total NULL NULL -1 14318180 0
    19 \\ServerName PhysicalDisk Disk Write Bytes/sec 272696576 -4 0 C: D: E: NULL NULL -1 14318180 0
    20 \\ServerName PhysicalDisk Disk Transfers/sec 272696320 0 _Total NULL NULL -1 14318180 0
    21 \\ServerName PhysicalDisk Disk Transfers/sec 272696320 0 0 C: D: E: NULL NULL -1 14318180 0
    22 \\ServerName PhysicalDisk % Disk Write Time 542573824 0 _Total NULL NULL -1 10000000 0
    23 \\ServerName PhysicalDisk % Disk Write Time 542573824 0 0 C: D: E: NULL NULL -1 10000000 0
    24 \\ServerName Network Interface Bytes Received/sec 272696576 -4 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter NULL NULL -1 14318180 0
    25 \\ServerName Network Interface Bytes Received/sec 272696576 -4 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] NULL NULL -1 14318180 0
    26 \\ServerName Network Interface Bytes Received/sec 272696576 -4 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter _3 NULL NULL -1 14318180 0
    27 \\ServerName Network Interface Bytes Received/sec 272696576 -4 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter _2 NULL NULL -1 14318180 0
    28 \\ServerName Network Interface Bytes Received/sec 272696576 -4 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter _4 NULL NULL -1 14318180 0
    29 \\ServerName Network Interface Bytes Received/sec 272696576 -4 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _4 NULL NULL -1 14318180 0
    30 \\ServerName Network Interface Bytes Received/sec 272696576 -4 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _3 NULL NULL -1 14318180 0
    31 \\ServerName Network Interface Bytes Received/sec 272696576 -4 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _2 NULL NULL -1 14318180 0
    32 \\ServerName Network Interface Bytes Sent/sec 272696576 -4 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter NULL NULL -1 14318180 0
    33 \\ServerName Network Interface Bytes Sent/sec 272696576 -4 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] NULL NULL -1 14318180 0
    34 \\ServerName Network Interface Bytes Sent/sec 272696576 -4 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter _3 NULL NULL -1 14318180 0
    35 \\ServerName Network Interface Bytes Sent/sec 272696576 -4 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter _2 NULL NULL -1 14318180 0
    36 \\ServerName Network Interface Bytes Sent/sec 272696576 -4 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter _4 NULL NULL -1 14318180 0
    37 \\ServerName Network Interface Bytes Sent/sec 272696576 -4 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _4 NULL NULL -1 14318180 0
    38 \\ServerName Network Interface Bytes Sent/sec 272696576 -4 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _3 NULL NULL -1 14318180 0
    39 \\ServerName Network Interface Bytes Sent/sec 272696576 -4 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _2 NULL NULL -1 14318180 0
    40 \\ServerName Network Interface Bytes Total/sec 272696576 -4 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter NULL NULL -1 14318180 0
    41 \\ServerName Network Interface Bytes Total/sec 272696576 -4 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] NULL NULL -1 14318180 0
    42 \\ServerName Network Interface Bytes Total/sec 272696576 -4 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter _3 NULL NULL -1 14318180 0
    43 \\ServerName Network Interface Bytes Total/sec 272696576 -4 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter _2 NULL NULL -1 14318180 0
    44 \\ServerName Network Interface Bytes Total/sec 272696576 -4 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter _4 NULL NULL -1 14318180 0
    45 \\ServerName Network Interface Bytes Total/sec 272696576 -4 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _4 NULL NULL -1 14318180 0
    46 \\ServerName Network Interface Bytes Total/sec 272696576 -4 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _3 NULL NULL -1 14318180 0
    47 \\ServerName Network Interface Bytes Total/sec 272696576 -4 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _2 NULL NULL -1 14318180 0
    48 \\ServerName Network Interface Output Queue Length 65792 0 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter NULL NULL -1 14318180 0
    49 \\ServerName Network Interface Output Queue Length 65792 0 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] NULL NULL -1 14318180 0
    50 \\ServerName Network Interface Output Queue Length 65792 0 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter _3 NULL NULL -1 14318180 0
    51 \\ServerName Network Interface Output Queue Length 65792 0 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter _2 NULL NULL -1 14318180 0
    52 \\ServerName Network Interface Output Queue Length 65792 0 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter _4 NULL NULL -1 14318180 0
    53 \\ServerName Network Interface Output Queue Length 65792 0 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _4 NULL NULL -1 14318180 0
    54 \\ServerName Network Interface Output Queue Length 65792 0 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _3 NULL NULL -1 14318180 0
    55 \\ServerName Network Interface Output Queue Length 65792 0 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _2 NULL NULL -1 14318180 0
    56 \\ServerName Network Interface Current Bandwidth 65792 -6 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter NULL NULL -1 14318180 0
    57 \\ServerName Network Interface Current Bandwidth 65792 -6 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] NULL NULL -1 14318180 0
    58 \\ServerName Network Interface Current Bandwidth 65792 -6 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter _3 NULL NULL -1 14318180 0
    59 \\ServerName Network Interface Current Bandwidth 65792 -6 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter _2 NULL NULL -1 14318180 0
    60 \\ServerName Network Interface Current Bandwidth 65792 -6 TEAM : Team _0 - Intel[R] PRO_1000 PT Dual Port Server Adapter _4 NULL NULL -1 14318180 0
    61 \\ServerName Network Interface Current Bandwidth 65792 -6 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _4 NULL NULL -1 14318180 0
    62 \\ServerName Network Interface Current Bandwidth 65792 -6 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _3 NULL NULL -1 14318180 0
    63 \\ServerName Network Interface Current Bandwidth 65792 -6 Broadcom BCM5708C NetXtreme II GigE [NDIS VBD Client] _2 NULL NULL -1 14318180 0
    64 \\ServerName Memory % Committed Bytes In Use 537003008 0 NULL NULL NULL NULL 14318180 0
    65 \\ServerName Memory Available MBytes 65792 0 NULL NULL NULL NULL 14318180 0
    66 \\ServerName Memory Committed Bytes 65792 -6 NULL NULL NULL NULL 14318180 0
    67 \\ServerName ASP.NET Requests Current 65536 -1 NULL NULL NULL NULL 14318180 0
    68 \\ServerName ASP.NET Worker Process Restarts 65536 -1 NULL NULL NULL NULL 14318180 0
    69 \\ServerName ASP.NET Applications Running 65536 -1 NULL NULL NULL NULL 14318180 0
    70 \\ServerName ASP.NET Requests Queued 65536 -1 NULL NULL NULL NULL 14318180 0
    71 \\ServerName ASP.NET Application Restarts 65536 -1 NULL NULL NULL NULL 14318180 0
    72 \\ServerName ASP.NET Worker Processes Running 65536 -1 NULL NULL NULL NULL 14318180 0
    73 \\ServerName ASP.NET Request Execution Time 65536 -1 NULL NULL NULL NULL 14318180 0
    Put that together with the Actual CounterData in the appropriately named table.
    GUID CounterID RecordIndex CounterDateTime CounterValue FirstValueA FirstValueB SecondValueA SecondValueB MultiCount
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 1 2015-04-30 13:01:17.165 0 -1927979745 2 -598728243 706 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 2 2015-04-30 13:01:22.173 67581.3633745449 -1927642227 2 -527219720 706 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 3 2015-04-30 13:01:27.165 94686.4063445727 -1927169543 2 -455741935 706 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 4 2015-04-30 13:01:32.172 152203.041104636 -1926407371 2 -384042212 706 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 5 2015-04-30 13:01:37.180 165447.09804292 -1925578898 2 -312344215 706 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 6 2015-04-30 13:01:42.172 171837.776053684 -1924721043 2 -240864459 706 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 7 2015-04-30 13:01:47.180 173383.630948422 -1923852824 2 -169166134 706 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 8 2015-04-30 13:01:52.172 144598.914838348 -1923130989 2 -97690055 706 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 9 2015-04-30 13:01:57.179 174737.727857169 -1922255986 2 -25991455 706 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 10 2015-04-30 13:02:02.171 169321.861725293 -1921410708 2 45486867 707 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 11 2015-04-30 13:02:07.179 208117.127073016 -1920368562 2 117185118 707 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 12 2015-04-30 13:02:12.171 141008.757157554 -1919664632 2 188662923 707 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 13 2015-04-30 13:02:17.178 149495.458222544 -1918916026 2 260361927 707 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 14 2015-04-30 13:02:22.170 174341.539879002 -1918045605 2 331847154 707 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 15 2015-04-30 13:02:27.178 143957.916530014 -1917324818 2 403537258 707 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 16 2015-04-30 13:02:32.170 130619.882518362 -1916672720 2 475018386 707 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 17 2015-04-30 13:02:37.178 142332.32395318 -1915959971 2 546718673 707 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 18 2015-04-30 13:02:42.170 184550.944997403 -1915038722 2 618192753 707 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 19 2015-04-30 13:02:47.177 154267.317838657 -1914266244 2 689889592 707 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 20 2015-04-30 13:02:52.169 149238.629713526 -1913521218 2 761368514 707 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 21 2015-04-30 13:02:57.177 188584.542348845 -1912576880 2 833066869 707 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 22 2015-04-30 13:03:02.169 176918.705027469 -1911693639 2 904548308 707 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 23 2015-04-30 13:03:07.176 188369.179859497 -1910750431 2 976242743 707 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 24 2015-04-30 13:03:12.168 148606.905306921 -1910008537 2 1047723754 707 1
    8ADCC3A7-4D90-45A3-B912-FB18C9CB3646 1 25 2015-04-30 13:03:17.176 200078.077196397 -1909006668 2 1119420468 707 1
    The query above is working, but I feel there is a better way to get this done.
    Sample Output:
    CounterDateTime ComputerName Counter CounterValue
    2015-04-30 13:01:00 ServerName Memory\Committed Bytes 23836753920
    2015-04-30 13:01:00 ServerName Memory\Committed Bytes 23837396992
    2015-04-30 13:01:00 ServerName Memory\Committed Bytes 23842693120
    2015-04-30 13:01:00 ServerName Memory\Committed Bytes 23843172352
    2015-04-30 13:01:00 ServerName Memory\Committed Bytes 23861657600
    2015-04-30 13:01:00 ServerName Memory\Committed Bytes 23872827392
    2015-04-30 13:01:00 ServerName Memory\Committed Bytes 23909138432
    2015-04-30 13:01:00 ServerName Memory\Committed Bytes 23960690688
    2015-04-30 13:01:00 ServerName Memory\Committed Bytes 23972872192
    2015-04-30 13:01:00 ServerName PhysicalDisk(_Total)\Current Disk Queue Length 0
    2015-04-30 13:01:00 ServerName Processor(_Total)\% Processor Time 0
    2015-04-30 13:01:00 ServerName Processor(_Total)\% Processor Time 8.65725297547727
    2015-04-30 13:01:00 ServerName Processor(_Total)\% Processor Time 9.34837740384615
    2015-04-30 13:01:00 ServerName Processor(_Total)\% Processor Time 10.45515625
    2015-04-30 13:01:00 ServerName Processor(_Total)\% Processor Time 11.3926622596154
    2015-04-30 13:01:00 ServerName Processor(_Total)\% Processor Time 11.4480309928908
    2015-04-30 13:01:00 ServerName Processor(_Total)\% Processor Time 11.8893621695024
    2015-04-30 13:01:00 ServerName Processor(_Total)\% Processor Time 12.3306933461139
    2015-04-30 13:01:00 ServerName Processor(_Total)\% Processor Time 13.3301821231728
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Received/sec 0
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Received/sec 67581.3633745449
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Received/sec 94686.4063445727
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Received/sec 144598.914838348
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Received/sec 152203.041104636
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Received/sec 165447.09804292
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Received/sec 171837.776053684
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Received/sec 173383.630948422
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Received/sec 174737.727857169
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Total/sec 0
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Total/sec 354821.47994974
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Total/sec 533111.927106303
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Total/sec 849787.130317823
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Total/sec 1015485.82303199
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Total/sec 1286054.48388504
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Total/sec 1528398.33137765
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Total/sec 1600789.68540725
    2015-04-30 13:01:00 ServerName Web Service(AppName)\Bytes Total/sec 1690894.89372096
    2015-04-30 13:02:00 ServerName Memory\Committed Bytes 23781527552
    2015-04-30 13:02:00 ServerName Memory\Committed Bytes 23802056704
    2015-04-30 13:02:00 ServerName Memory\Committed Bytes 23803797504
    2015-04-30 13:02:00 ServerName Memory\Committed Bytes 23821389824
    2015-04-30 13:02:00 ServerName Memory\Committed Bytes 23831420928
    2015-04-30 13:02:00 ServerName Memory\Committed Bytes 23835803648
    2015-04-30 13:02:00 ServerName Memory\Committed Bytes 23850049536
    2015-04-30 13:02:00 ServerName Memory\Committed Bytes 23863857152
    2015-04-30 13:02:00 ServerName Memory\Committed Bytes 23875534848
    2015-04-30 13:02:00 ServerName Memory\Committed Bytes 23917281280
    2015-04-30 13:02:00 ServerName Memory\Committed Bytes 23933739008
    2015-04-30 13:02:00 ServerName Memory\Committed Bytes 23978917888
    I hope this additional information I have provided will help. :)
    Thanks for your time!

  • What's the best way for reading this binary file?

    I've written a program that acquires data from a DAQmx card and writes it on a binary file (attached file and picture). The data that I'm acquiring comes from 8 channels, at 2.5MS/s for, at least, 5 seconds. What's the best way of reading this binary file, knowing that:
    -I'll need it also on graphics (only after acquiring)
    -I also need to see these values and use them later in Matlab.
    I've tried the "Array to Spreadsheet String", but LabView goes out of memory (even if I don't use all of the 8 channels, but only 1).
    LabView 8.6
    Solved!
    Go to Solution.
    Attachments:
    AcquireWrite02.vi ‏15 KB
    myvi.jpg ‏55 KB

    But my real problem, at least now, is how can I divide the information to get not only one graphic but eight?
    I can read the file, but I get this (with only two channels):
    So what I tried was, using a for loop, saving 250 elements in different arrays and then writing it to the .txt file. But it doesn't come right... I used 250 because that's what I got from the graphic: at each 250 points it plots the other channel.
    Am I missing something here? How should I treat the information coming from the binary file, if not the way I'm doing?
    (attached are the .vi files I'm using to save in the .txt format)
    (EDITED. I just saw that I was dividing my graph's data in 4 just before plotting it... so It isn't 250 but 1000 elements for each channel... Still, the problem has not been solved)
    Message Edited by Danigno on 11-17-2008 08:47 AM
    Attachments:
    mygraph.jpg ‏280 KB
    Read Binary File and Save as txt - 2 channels - with SetFilePosition.vi ‏14 KB
    Read Binary File and Save as txt - with SetFilePosition_b_save2files_with_array.vi ‏14 KB

  • Whats the best way to expose this in memory database? (ArrayList)

    Hello everyone.
    I was looking for advice on how I should implement this...currently I have the following ArrayList that stores ClassEntity objects. I'm going to write 2 classes that need to access this ClassEntity Object arrayList because they are goign to use these objects to spit out 2 different files.
    I didn't want to make the database public and static though.
    Here's a snippet of my current class that populates and creates the arrayList data structure:
    public class RODMFileParser
         //used to keep file information
         ClassEntity classEntity = null;
         //used to store ClassEntity objects
         List<ClassEntity> classEntityList = new ArrayList<ClassEntity>();
         //used to store the conversion table RODM->ENGLISH/ENGLISH->RODM
         ConversionTableParser convTableParser = new ConversionTableParser();
            else if(line.contains("Field Value "))
                        //now we can create a new Entity Class object! tricky! huh
                        classEntityList.add(new ClassEntity(idClassName,  idFieldName,
                                                                       englishClassName, englishFieldName, fieldType));
    Iterator listIter = classEntityList.iterator();
              while(listIter.hasNext())
                   ClassEntity tempObj = (ClassEntity) listIter.next();
                   System.out.println(tempObj);
              }So now classEntityList has all the objects I need to create these 2 seperate files but these 2 files are dramtically different. What would be the best way at exposing this classEntityList ArrayList so my 2 other classes can access it?
    Thanks!

    well if I made it non-static, wouldn't I have to create a new object of that class in each class I want to use it in?
    for example, that class that populates the database must parse a file to create the database.
    RODMFileParser file = new RODMFileParser();
              file.parseFile("QAGENT");So inside each class I would have to do this wouldn't I? if I made it public static, wouldn't I only have to read to the disk once?
    Putting it to a worst case say, 100 classes need this database, that means I would have to make 100 accesses to the disk woulnd't it?
    And if it was public static, it would jsut return a copy of the database that was only read from the disk once or am I misunderstanding how it works?

  • Event Structures​-best way to implement this UI?

    I am trying to write a VI to control & read data from 4 different "channels" (each measuring a DUT) at once.  I have written all the VI's for initializing instruments, communicating with the devices (VISA, GPIB), setting bias, reading data, etc...that has all completed. I just need to write the overall program with the user interface to allow the user to control these 4 channels & display the measured data.....as it turns out, this is the tricky part! My head is spinning from trying to figure out how to handle all the possible events.
    Basically for each channel, I want the user to be able to
    -enable/disable it  for measurement (e.g. if  there is no device loaded in Ch.3, we don't want to measure Ch.3..maybe disable/grey everything)
    -set bias conditions (only if channel enabled). Allow user to change bias "in real-time" by increment/decrementing (e.g. incrementing from 5.00 V to 5.01 V, for example).
    -turn biasing on/off (again, only if channel is enabled)
    Also,  I want each channel to display its measured data (e.g current, temperature reading)..every second or so. No graphs or anything fancy (for now! ), just numeric indicator. 
    Honestly, this all sounds so simple but I'm having trouble figuring out the best way to implement this, due to the fact that 1) there are multiple channels needing to be monitored for events  2) large number of user events that could occur (seems like at least 4 per channel - enabling/disabling, turning bias on/off, incrementing/decrementing bias values, etc ), Also the if a channel IS enabled, i want to be continously reading/displaying the data.  What is the best way to handle this? Should i have 4 separate while loops, each with an event structure to handle events for that particular channel..or will that give me grief somewhre? 
    Also, I have another nagging question. Pretty much all the examples I see re: Event Structures and booleans involve latched booleans, eg. buttons that are just pressed once and pop back up...e.g. buttons you press to tell it to complete a task (e.g. "Acquire Data" or "Stop") , and once it's pressed it's over and reset.  In my case, some of the booleans would not be latched...e.g. the "Enable Ch.2" button would be 'TRUE" as long as i want Ch. 2 to be read....does that make sense? Then, say hours later,  if i did want to disable that channel,  i would change it to "FALSE" and while that would be an "value change", the new value would not be "TRUE"..does that make sense? So  not sure if that would be dealt with the same way in an Event Structure. 
    Hope this all makes sense and many thanks in advance for any help!!!

    You're halfway there. I'd say the best solution is a producer/consumer structure, the event structure is used to generate queued commands to the consumer loop.
    All data is handled in the consumer loop, where you among other things have an array of clusters of channel/instrument settings. (I usually have several cluster, one for test data, one for instrument settings, one for general settings and so on)
    The event structure can have a 1 sec timeout, in which you queue up a Measure command.
    In the consumer, in the measure state you loop through your instruments and if enabled you measure them and update their indicators.
    The general (smart) way to setup the queue is with a cluster containing 2 elements, a typedef'd Command and a variant.
    This way you can send data with the command in any form which is then interpreted in the consumer.
    If, e.g. you press the Enable button on a channel, you can enqueue Enable and the channel number.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • Best way to write specific information to a file

    Hi there,
    I'm looking to write specific information from my program to 2 separate files.
    Before the program runs, it asks the operator for their info (name, password, run ID #, a couple safety checkboxes).
    So, I would like the first file to record log-in information (i.e. The operator's name, the date and time they accessed the program, and the Run ID #) all in a spreadsheet.
    I would like the second file to record data from the different components of the program ( 2 tank levels, a flow meter, and run ID #) in another spreadsheet.
    Any thoughts on the best way to do this? I've looked at using arrays to organize the info/data, and then write to spreadsheet, but I haven't quite figured it out...
    Thanks,
    Daryn

    For the first, you could convert everything to strings, then send an array of strings. For the second, just send an array of numbers.
    Cameron
    To err is human, but to really foul it up requires a computer.
    The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
    Profanity is the one language all programmers know best.
    An expert is someone who has made all the possible mistakes.
    To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):
    LabVIEW Unit 1 - Getting Started
    Learn to Use LabVIEW with MyDAQ

  • Best way to write an Wrapper class around a POJO

    Hi guys,
    What is the best way to write an Wrapper around a Hibernate POJO, given the latest 2.2 possibilities? The goal is, of course, to map 'regular' Java Bean properties to JavaFX 2 Properties, so that they can be used in GUI.
    Thanks!

    what about this:
    import javafx.beans.property.SimpleStringProperty;
    import javafx.beans.property.StringProperty;
    public class PersonPropertyWrapper {
         private StringProperty firstName;
         private StringProperty lastName;
         private Person _person;
         public PersonPropertyWrapper(Person person) {
              super();
              this._person = person;
              firstName = new SimpleStringProperty(_person.getFirstName()) {
                   @Override
                   protected void invalidated() {
                        _person.setFirstName(getValue());
              lastName = new SimpleStringProperty(_person.getLastName()) {
                   @Override
                   protected void invalidated() {
                        _person.setLastName(getValue());
         public StringProperty firstNameProperty() {
              return firstName;
         public StringProperty lastNameProperty() {
              return lastName;
         public static class Person {
              private String firstName;
              private String lastName;
              public String getFirstName() {
                   return firstName;
              public void setFirstName(String firstName) {
                   this.firstName = firstName;
              public String getLastName() {
                   return lastName;
              public void setLastName(String lastName) {
                   this.lastName = lastName;
         public static void main(String[] args) {
              Person p = new Person();
              p.setFirstName("Jim");
              p.setLastName("Green");
              PersonPropertyWrapper wrapper = new PersonPropertyWrapper(p);
              wrapper.firstNameProperty().setValue("Jerry");
              System.out.println(p.getFirstName());
    }Edited by: 906680 on 2012-7-27 上午10:56

  • How do I write this SQL command in Oracle

    Hi all
    I wriote this SQ L statement in Ms SQL Server. How do I write this sql command in Oracle?
    ALTER VIEW dbo.ConsumptionAS SELECT TOP 100 PERCENT ID,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200710' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Oct2007,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200711' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Nov2007,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200712' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Dec2007,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200801' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Jan2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200802' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Feb2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200803' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Mar2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200804' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Apr2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200805' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS May2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200806' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Jun2008 ,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200807' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Jul2008 ,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200808' AND NbrDaysUsed != 0 THEN (QtyUsed/ NbrDaysUsed) * 748.05 ELSE 0 END)) AS Aug2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200809' AND NbrDaysUsed != 0 THEN (QtyUsed NbrDaysUsed) * 748.05 ELSE 0 END)) AS Sep2008
    FROM dbo.MasterConsumption WHERE YEAR_MONTH >= '200710' AND YEAR_MONTH <= '200809' GROUP BY ID ORDER BY ID
    I am very interested in this part:
    SUM(CASE WHEN YEAR_MONTH = '200710' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Oct2007
    thanks
    Edited by: user631364 on Oct 27, 2008 8:25 AM
    Edited by: user631364 on Oct 27, 2008 8:26 AM
    Edited by: user631364 on Oct 27, 2008 8:27 AM

    Thank you!!
    Now let me aslk the second part of my question.
    This sql command:
    ALTER VIEW dbo.ConsumptionAS SELECT TOP 100 PERCENT ID,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200710' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Oct2007,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200711' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Nov2007,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200712' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Dec2007,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200801' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Jan2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200802' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Feb2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200803' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Mar2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200804' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Apr2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200805' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS May2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200806' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Jun2008 ,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200807' AND NbrDaysUsed != 0 THEN (QtyUsed/ Days_Usage) * 748.05 ELSE 0 END)) AS Jul2008 ,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200808' AND NbrDaysUsed != 0 THEN (QtyUsed/ NbrDaysUsed) * 748.05 ELSE 0 END)) AS Aug2008,
    CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = '200809' AND NbrDaysUsed != 0 THEN (QtyUsed NbrDaysUsed) * 748.05 ELSE 0 END)) AS Sep2008
    FROM dbo.MasterConsumption WHERE YEAR_MONTH >= '200710' AND YEAR_MONTH <= '200809' GROUP BY ID ORDER BY ID
    was created with this query in SQL Server and then I saved it in a store procedure, that I scheduled to run montlhy
    SET ANSI_NULLS ON
    DECLARE @SQLString NVARCHAR(4000)
    /* Build the SQL string once.*/
    SET @SQLString = 'ALTER VIEW dbo.Consumption AS SELECT TOP 100 PERCENT ID, CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = ' +
    "'" + dbo.CONLastMonth_fn(getdate(), month(getdate()) - 12) +
    "'" +
    ' AND NbrDaysUsed != 0 THEN (QtyUsed/ NbrDaysUsed) * 748.05 ELSE 0 END)) AS ' +
    dbo.CONMonthInEnglish(getdate(), month(getdate()) - 12) +
    … (GOES FROM current month -12 to current month -1)
    , CONVERT(decimal(10, 2), SUM(CASE WHEN YEAR_MONTH = ' +
    "'" + dbo.CONLastMonth_fn(getdate(), month(getdate()) - 1) +"'" +
    ' AND NbrDaysUsed != 0 THEN (QtyUsed/ NbrDaysUsed) * 748.05 ELSE 0 END)) AS ' +
    dbo.CONMonthInEnglish(getdate(), month(getdate()) - 1) +
    ' FROM dbo.MasterConsumption WHERE YEAR_MONTH >= ' +
    "'" + dbo.CONLastMonth_fn (getdate(), month(getdate())-12 ) +"'" +
    ' AND YEAR_MONTH <= ' +
    "'" + dbo.CONLastMonth_fn (getdate(), month(getdate())-1 ) +"'" +
    ' GROUP BY ID ORDER BY ID '
    EXEC sp_executesql @SQLString
    Is that something that can be done in Oracle in the same way?
    Do you use another approach?
    please advice
    Edited by: user631364 on Oct 27, 2008 10:19 AM
    Edited by: user631364 on Oct 27, 2008 10:21 AM
    Edited by: user631364 on Oct 27, 2008 10:21 AM
    Edited by: user631364 on Oct 27, 2008 10:22 AM
    Edited by: user631364 on Oct 27, 2008 10:23 AM
    Edited by: user631364 on Oct 27, 2008 10:23 AM
    Edited by: user631364 on Oct 27, 2008 10:24 AM

Maybe you are looking for

  • Print part of a page for book

    I have a book in a pdf file that was converted from Cork. The pdf file has lines on each corner and show when i print it. Is there a way to highlight a section of the page and print just that section for all pages? Or a way to zoom in and print the v

  • Unable to restore my iPad via iTunes

    Hi guys, I am looking for help to restore my iPad. I tried to restore my iPad via iTunes on PC in the morning, however, the process of downloading Apple software update was stopped at the last mintue as it was almost completed. iTunes popped up " Tim

  • Imort to iCal

    I have been using a Sony Clie (Palm OS 4.01) on Windows XP. Now I have a new MacBook and want to transfer the data to iCal. Can this be done? How? Thanks.

  • What power line adapters work with the Simpler Net...

    I currently use the provided Simpler Networks power line adapters, one plugged into my HH3 and the other for my BT Vision box. I want to also connect my desktop PC to the HH suing a power line adapter. Which ones will work with the ones I already hav

  • Is my macbook 32bit or 64bit?

    Hardware Overview:   Model Name:          MacBook   Model Identifier:          MacBook5,1   Processor Name:          Intel Core 2 Duo   Processor Speed:          2 GHz   Number Of Processors:          1   Total Number Of Cores:          2   L2 Cache: