Print out a column value only if another column has a specific value (CASE Statement)

Hello all,
I tried many hours to find a solution for the following request but wasn't successful. Maybe you could help me.
I've using the already existing SQL Views in Microsoft Service Manager to do some basic reporting about my tickets.There is no closed date in the activity tickets so I decided to print out the lastmodified timestamp when the status is "closed".
That's my query:
SELECT DISTINCT
dbo.DisplayStringView.DisplayName AS Status,
CASE WHEN dbo.DisplayStringView.DisplayName = 'Closed' THEN dbo.DisplayStringView.LastModified ELSE 'NO CLOSED Date' END AS ClosedDate
FROM dbo.MTV_System$WorkItem$Activity$ManualActivity LEFT OUTER JOIN
dbo.DisplayStringView ON dbo.MTV_System$WorkItem$Activity$ManualActivity.Status_8895EC8D_2CBF_0D9D_E8EC_524DEFA00014 = dbo.DisplayStringView.LTStringId
Unfortunatelly I'm not getting the value from dbo.DisplayStringView.LastModified. SQL outputs that it is not possible to convert the string to date/time.
I think there is a problem with the CASE statement in combination with a value select.
Any ideas how to print out a column value only if another column has a specific value?

I think it is the other way if you want the missing date shown as a string.
CASE
WHEN
dbo.DisplayStringView.DisplayName
=
'Closed'
THEN
Convert( varchar(10),dbo.DisplayStringView.LastModified
, 101) ELSE
'NO CLOSED Date'
END
AS
ClosedDate 

Similar Messages

  • Restrict print out of Purchase order only for Production system

    Hi,
    I want to restrict print out of Purchase order only for Production system, don't want to take it in devep or quality.
    is there any identifier to find the system is production or development.
    can anyone tell me how to restrict it,
    is there any function module, not based on client system.
    Thanx in advance
    Kesav

    Hi Kesavarathinam Vaidyalingam ,
    yes, I also use thomas' suggestion using
    t000-cccategory = 'P'.
    to determine productive client.
    Just one small hint: I found this condition as true in a test system: The admin had done a system copy to create a fresh test client - but forgot (or did not see a good reason) to change t000-cccategory = 'P. to  t000-cccategory = 'T'.
    Regards,
    Clemens

  • How can I add new values only to a column of a spreadsheet?

    I have three "while loops" that are executed in parallel, two generate values and the third while loop write the values in a spreadsheet.
    The run time of each while loop is different, to synchronize the three while loops I use a "Wait Until Next ms Multiple", but sometimes the same value is kept twice.
    I think that a solution would be to add a "Write To Spreadsheet File" in the blocks that generate values, adding a new value in the wished column in each cycle, but I do not know like doing this.
    I could keep the values in two arrays and add them in a same spreadsheet in different rows or columns, but I need save values in spreadsheet in each loop and not all values at the end of cycle.
    Thanks.
    German Garrigos.

    I think your three loops solution is probably better than putting different kinds of functions into one loop. Keeping data acquisition/generation separate from file i/o is usually better because the OS can interfere with timing on the file operations.
    If you pass the data to the file loop via queues, place the data into shift registers, and only write to the file when you have equal amounts of data from each generator you should be able to keep things synchronized. You can write larger or smaller amounts as necessary to keep pace with the generators. If one of the generators gets way ahead of the other, you have to decide how to deal with that issue.
    Writing to the second column of a three column spreadsheet can be tricky. It involves keeping pointers to the portions written and not written, reading the entire file into memory and overwriting the cells where new data goes and rewriting the entire file. This can get very slow for large files. If the file and data structures are simple enough it might be feasible to read only a portion of the file and overwrite it with new data, but that approach has lots of risks to the data.
    Wait until next ms multiple is only reliable if the wait interval is sufficiently longer than the execution time (including random OS delays) of each loop. Look at the synchronization functions such as notifiers to synchronize your loops.
    If you still have problems, post a simplified version of your program and someone will probably be able to suggest solutions.
    Lynn

  • How to concatinate values of two columns and update into another column

    There is a table : TEST contains three columns - Column1 , Column2 , Column 3
    Column1 contains values - (1,2,4)
    Column2 contains values : (a,b,c)
    Column 3 is empty .
    Target : Values in column 3 should be (1a,2b,4c)
    Need to achieve this through procedure .

    Paul if i want to concatenate two strings or alpha numeric characters from 2 fields and display in the third field,Will this code be able to do that?

  • Auto populating a column prompt based on another column prompt

    Hi,
    Is it possible to auto-populate a column prompt, using the value of another column prompt?
    My situation is described as below.
    I have created a new dashboard prompt. This contains 2 column prompts, for example say col1 and col2. Both are multi-select prompts.
    col1 values - a,b,c,d.....
    col2 values - 5,2,8,7.....
    col1 and col2 values are picked from different tables. Also we have a mapping table which maps col1 and col2. Say a-5, b-10, c-1, d-3 etc...
    My requirement is, if a user selects values "a,d" for col1 prompt, col2 prompt must be automatically populated by values "5,3".
    Is this possible? If so, please help.
    Thanks,
    kc.

    If the actual filter criteria is only col1 the instead of displaying the values in the second prompt, make a separate report and only choose only the 2nd col in that report and make col1 as prompted and select appropriate title for that report.Place the report above the actual report in dashboard. So it will display only those records which are chosen in col1 from the prompt.

  • How to re-calculate a column value based on another column value in the same ADF Table row

    Hi,
    I'm using Jdeveloper 11.1.2.3.0.
    I have an adf table with 2 columns, columnA and columnB.
    When the value changed in ColumnA,
    1) i need to call a PLSQL and update the ColumnB value that is returned from PLSQL.
    2) Show a warning message if the existing value in ColumnB is different from the one that is returned from PLSQL.
    Can anybody suggest how can i accomplish this?
    Thanks,
    Vinod

    hi user,
    if you have inputtext means have a valuechangelistener
    in that call your pl/sql function supply input value to the appropriate function then grab the result of the function. then bind the column inputtext and compare with it. then raise your warning using FacesMessage classes.
    Sameh Nassar: Create PL/SQL Function And Call It From Your ADF Application

  • Best way to select distinct values based on another column?

    I have a table with three columns: id (NUMBER), data_dt (DATE), and data_value (NUMBER).
    There is a primary key on id and data_dt.
    I want to select the record with the latest data_dt for each unique id.
    What is the best way to do this?
    I have three different methods, but there may be something I am missing.
    First:
    SELECT *
    FROM
      SELECT id, data_dt, data_value,
             FIRST_VALUE(data_dt)
             OVER (PARTITION BY id ORDER BY data_dt DESC) AS last_data_dt
      FROM the_table
    WHERE data_dt = last_data_dt;(I use ORDER BY...DESC instead of just ORDER BY so I don't need the ROWS BETWEEN clause)
    Second:
    SELECT t1.*
    FROM the_table t1
    JOIN
      SELECT id, MAX(data_dt) AS last_data_dt
      FROM the_table
      GROUP BY id
    ) t2 ON (t2.id = t1.id AND t2.data_dt = t1.data_dt);Third:
    SELECT t1.*
    FROM the_table t1
    WHERE t1.data_dt =
      SELECT MAX(t2.data_dt)
      FROM the_table t2
      WHERE t2.id = t1.id
    );-- Don

    Hi,
    There are more possible scenario's, for example:
    select t1.*
    from   the_table t1
    where not exists ( select null
                       from   the_table t2
                       and    t2.data_dt > t1.data_dt
    What is the best way to do this?Only you can tell:
    Test all scenario's, check the execution plans, set timing on and pick the best/fastest one ;-)
    If it's not clear, please post the execution plans here.

  • HowTO: Get only one entry which has the highest value in a specific column?

    Hi there,
    ich have the following problem. I want to write logs in a table. One column is the date of the log and some others hold the information.
    Now I want to get the last log and I it should be good performance too.
    What would you suggest?
    At the moment I think about the max() function. Is it a solution?
    Would a view which orders the logs by date (DESC) improve performance? maybe the view could create a collum which numbers the logs beginning by the newest.
    something like: ...ROW_NUMBER() OVER(ORDER BY logdate) AS indx ...
    Thx in advance
    Dominik

    In my opinion SELECT * FROM MY_LOG WHERE LOG_DATE =
    MAX(LOG_DATE) could be expensive (performance)In the first place, it issues an error saying GROUP functions are not allowed here.
    MAX() solution would be better.
    SQL> explain plan for select *
      2                   from (select emp.* , row_number() over (order by hiredate desc) rn
      3                         from emp)
      4                   where rn = 1;
    Explained.
    SQL>
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id  | Operation                |  Name       | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT         |             |    16 |  1760 |     4 |
    |*  1 |  VIEW                    |             |    16 |  1760 |     4 |
    |*  2 |   WINDOW SORT PUSHED RANK|             |    16 |   704 |     4 |
    |   3 |    TABLE ACCESS FULL     | EMP         |    16 |   704 |     2 |
    Predicate Information (identified by operation id):
       1 - filter("from$_subquery$_001"."RN"=1)
       2 - filter(ROW_NUMBER() OVER ( ORDER BY "EMP"."HIREDATE" DESC )<=1)
    Note: cpu costing is off
    17 rows selected.
    SQL>
    SQL> explain plan for select emp.* from emp
      2                   where hiredate = (select max(hiredate)
      3                                     from emp);
    Explained.
    SQL>
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id  | Operation            |  Name       | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT     |             |     1 |    44 |     2 |
    |*  1 |  TABLE ACCESS FULL   | EMP         |     1 |    44 |     2 |
    |   2 |   SORT AGGREGATE     |             |     1 |     9 |       |
    |   3 |    TABLE ACCESS FULL | EMP         |    16 |   144 |     2 |
    Predicate Information (identified by operation id):
       1 - filter("EMP"."HIREDATE"= (SELECT /*+ */
                  MAX("EMP"."HIREDATE") FROM "EMP" "EMP"))
    Note: cpu costing is off
    17 rows selected.
    SQL> Cheers
    Sarma.

  • Programatically Assigning Column Value Based on Another Column

    I have a problem as follows:
    My database table has the following setup:
    There may be many gift numbers the same, however many different recipient numbers for each gift.
    The receipient number should increment from 1-X based on the gift number, for example, if the gift number is the same then the receipient number should increment for that gift.
    Gift Number
    Recipient Number
    1
    1
    1
    2
    1
    3
    2
    1
    3
    1
    3
    2
    The programmatic code for inserting a new row would be:
    Check if gift number already exsists in database.
    -if it does exsist then find latest and increment current receipient number by one for receipment number
    -if it does not exsit set receipient number at 1
    How do i do this?
    JDEV - 11.1.2.4 (ADF BC)

    Your use case has some flaws which you should think about before trying to implement it.
    1) think about what happens if multiple users try to insert a record at the same time. What can happen? How do you want to handle this situation?
    2) do you really need the number to be gap less? The use case can be implemented easily if you don't have this restriction.
    3) The table should have the technical primary key to avoid pk clashes due to multiple inserts at one time.
    Now, if you have a technical pk as primary key, you can setup a unique key on both of the other columns which prevents that somehow you get duplicates there.
    You let the user insert the gift number and calculate the recipient number as max(recipient number)+1. Then you commit the record. If you don't get an error you are finished, if you get an error you add 1 to the recipient number and try to commit again, until the insert works.
    Timo

  • Taking info from Column and Pasting to another Column without losing content?

    Hi Numbers Masters,
    I am working on an e-commerce store CSV spreadsheet.
    For instance:
    I have column "A" which is a description of a product and column "B" which is a SKU Number. I want the SKU number column info to be added to Column "A" without deleting the description content in Column "A". There is different values for each SKU number in column B and different content for info in Column "A".
    If I copy and paste I lose the info in Column "A" and am just left with info from Column "B".
    THANK YOU

    In Excel I would do this
    Save a copy of the file.
    Concatenate the text by creating a formula in a third column that "adds" the contents of A and B.
    Then inspect the column
    I expect Numbers works similarly.
    Use the & function to add strings (Descriptions or SKU)
    Something like this
    A1 & B1
    A1 & " " & B1
    gives you a space
    A1 & " -" & B1
    gives you a dash
    Description
    SKU
    Combine
    Scissors
    1234
    Scissors 1234
    Clipboard
    78766
    Clipboard 78766
    Masking tape
    9832
    Masking tape 9832
    Scissors
    1234
    Scissors:1234
    Clipboard
    78766
    Clipboard:78766
    Masking tape
    9832
    Masking tape:9832

  • How do you integrate a column with respect to another column

    I have two columns of data, one is time and the other is velocity. I want to be able to integrate velocity with respect to time, but I can not find a function which will let me do this. Preferably, I'd like to do a cumulative trapezoidal integration, such as the one in Matlab. The function "cumtrapz" does not work the same in mathscript as it does in matlab. The "trapz" function did not seem to integrate the columns in the way that I wanted it to, leaving me with just a number.
    Is there any way I can recreate the "cumtrapz" function from Matlab in Mathscript?
    Thanks.

    The cumtrapz in MathScript can not accept a time array as input. Then, you have to write your own script to calculate the cumulative trapezoid integration. For example, the following script generates a sin wave and calculates the cumulative trapezoidal integration.
    t = 0:0.1:pi;
    x = sin(t);
    y = 0.5*(x(1:(end-1))+x(2:end)).*(t(2:end)-t(1:(end-1)​)); %trapizoidal integration
    y = cumsum(y); %cumulative sum

  • Making a new column out of the values from another column

    I am trying to query the transaction table and the promotion table to get the following output..
          select t.no, t.date,p.groupid,p.promocode,sum(t.salesamt)
          from trans t, promo p
          where t.id=p.tid
          group by t.no,p.groupid,p.promocode,t.date
          order by t.date
    no
    date
    groupid
    promocode
    promodesc
    sum(t.salesamt)
    m12
    01-jun-2012
    09
    p12
    Promotion1
    7890.00
    m12
    01-jun-2012
    09
    p13
    Promotion2
    345.56
    m12
    01-jun-2012
    09
    p14
    Promotion3
    2345.90
    m12
    01-jun-2012
    09
    p12
    Promotion1
    345.12
    m12
    01-jun-2012
    09
    p13
    Promotion2
    23678.00
    m12
    01-jun-2012
    09
    p14
    Promotion3
    3456.78
    I want to remove the promodesc and the sum(t.salesamt) and add Promotion1,Promotion2,Promotion3 as three new columns and their respective sum(t.salesamt) as their data value.
    I am thinking about using three separate case statements to achieve this...
    sum( case when promocode='p12' then t.salesamt end) Promotion 1
    Please let me know if there is any other optimal way to achieve this.
    Thank you!

    Hi,
    What you want is called a Pivot.  Using CASE expressions (like you described) is one common way to do pivots.  If you're using Oracle 11.1 (or higher) then you'd probably want to use the SELECT ... PIVOT feature instead.  See the SQL Language manual
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#sthref6809
    and the forum FAQ
    https://forums.oracle.com/message/9362005
    for details and examples.
    If you get stuck, post your best attempt, along with CREATE TABLE and INSERT statements for a little sample data, and the results you want from that data (if different from what you've already posted).
    Always say which version of Oracle you're using (for example, 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Need Help in Next value of column to another column

    Hi,
    I am creating view in oracle 10g in which i have 1 custom column who's value are the next value of the another column.
    E.g.
    C 1 -----C2 ------ custom-C3
    10 -------1 --------------2
    10 ------ 2 ------------- 3
    10 -------3 ------------- 3
    11 -------1 ------------- 2
    Now is there any function in oracle which gives me to generate "custom-c3"
    which gives the data for next value of column 2
    Thanks.

    Hi Frank,
    Thank you so much......its working fine in 10 g.....
    but for the last row of its coming emply or null but i want value of c2 if its last value.
    e.g
    C 1 -----C2 ------ custom-C3
    10 -------1 --------------2
    10 ------ 2 ------------- 3
    10 -------3 ------------- 3
    11 -------1 ------------- 2
    In the above the value of c1 is 10 i.e last one then value of c3 should be value of c2 i.e. 3.
    Can you use IF function?
    Thanks.
    Message was edited by:
    user650690

  • Change column value based on another

    Hi, everyone.
    my version 11.1.2.2.0.
    i wanna change 1 column's value based on another column's value that be selected.
    ex: select 2rd column to 'A' , then the 1rd should be 'New Start'.
    i used EL like #{row.bindings.MacdType.inputValue eq 1 ? 'New Start' :  row.bindings.CircuitId.inputValue}.
    But it does not set the inputvalue which should binding with the DataSource.
    what's the best way to do these logic?
    pls help. thx

    Hi,Abhijit;
    ex: the frist column is a LOV, the user select "A" for the first column, so the value of the second column should be changed to 'New Start'.
    And the value should be binding to the DC, when save, the value of the 2rd column should be saved to DB.
    thx

  • Library Filters: Filter for multiple values in a single column and Wildcards

    If you have a multi-value column in a library, can you filter to show only results where two (or more) specific values (terms) are applied? E.g. Year 2014 and Month January? Seems this would be particularly useful for Enterprise Keywords columns.
    Similarly, is there any way to filter on one value OR another value in a single column (e.g. Document Type Memo OR Fax)?
    Any way to use wildcards in searches (would be REALLY useful in the Title and Name columns when naming conventions have been followed).
    I'm guessing the answer is going to be 'move to SharePoint 2013' - if that is the case, please confirm whether all the scenarios mentioned above are catered for.

    Thanks for your replies !
    Is there any other way to achieve this ?
    There is 1 InfoObject which has 2 fields Employee and Department.
    Employee     Department
    001                A
    001                B
    001                C
    In the report there should be 1 row for Employee 001 with all the Departments displayed in the same cell separated by commas.
    Can this be done in the backend through a ABAP code?

Maybe you are looking for

  • What is the best way to hook up an external monitor? Im having some issues!

    Up until now I have been able to use my external monitor while editing. I recently got a 20" HDTV with HDMI and a jack to use it as a computer monitor. I notice that once I set my VIEW option to ALL FRAMES in FCP, it will only show me a frame at a ti

  • 10.1.3.4.0 : iterator mode : RowIterator.ITER_MODE_LAST_PAGE_FULL

    hi The ADF Developer's Guide For Forms/4GL Developers 10g Release 3 (10.1.3.0) section "27.1.4 Presenting and Scrolling Data a Page at a Time Using the Range" ... at http://download.oracle.com/docs/cd/B32110_01/web.1013/b25947/bcadvvo.htm#sthref2557

  • PO item with Multiple Goods receipt line items

    Hi Experts, When we create PO for specific vendor with one PO line item then at the time of Good receipt there are multiple GR line items. How to control those multiple GR line items as one GR item. Appreciated your help Regards Krishna

  • How to get the same colored labels as in the gmail web interface?

    Hi, I would like to get the same preview in Mail.app (with different colored labels) as in Gmail. Currently, my Gmail account in synced with Mail.app, hence I have access to all my mailboxes (hence all my labels). I would like to add a rule which rea

  • Logic Express and Waves Plugins?

    I have the waves gold bundle that i use with DP. Just got logic express to see if can make the swtich from DP. But all i really need is to be able to use my waves gold bundle. BUT I CANT. is this just becuase i am using LE? here is what happens... WH