EXPRESSION SYNTAX REQUIRED FOR DERIVED COLUMN

Hi
I've had a look around and can't find the correct syntax for an Expression in a Derived Column task.
Below is the logic in TSQL. Please could someone help me convert it?
CASE
WHEN FIELD1
=
'A'
AND FIELD2
IS
NULL
THEN
'A'
WHEN FIELD1
=
'B'
AND FIELD2
IS
NULL
THEN
'B'
WHEN FIELD1
=
'A'
AND FIELD2
=
'C'
THEN
'C_A'
WHEN FIELD1
=
'B'
AND FIELD2
=
'C'
THEN
'C_B'
WHEN FIELD1
=
'A'
AND FIELD2
=
'D'
THEN
'D_A'
WHEN FIELD1
=
'B'
AND FIELD2
=
'D'
THEN
'D_B'
ELSE
'0'
END
Thanks in advance
Lucy

Hi Lucy,
Try like below expression in derived columns.. 
 ((FIELD1 = 'A'
&& FIELD2 IS NULL)
? "A" :
  (FIELD1 = 'B'
&& FIELD2 IS NULL)
? "Y" :
(FIELD1 = 'A' && FIELD2 = 'C' )?
”C_A” :
(FIELD1 = 'B' && FIELD2 = 'C' )
? “'C_B” :
(FIELD1 = 'A' && FIELD2 = 'D' )
? “'D_A'” :
(FIELD1 = 'B' AND FIELD2 = 'D' )
? “'D_B”
: "0"))

Similar Messages

  • Expression for derived column

    Hi,
    In my SSRS package I have a field which may have a null value. I want to create a derived column that does the following:
    If the value is null replace with 0 else return the value
    How do I script this?The fiels is my [Qty Remaining] field. I thought it might have been something like this but I was obviously wrong:
    ISNULL([Qty Remaining])  ? "0" :  [Qty Remaining]
    Cheers
    Paul

    Try this
    ISNULL([number])  ? (DT_I4) "0" : [number]
    "0" is unicode string, you have to convert it to number, in my case integer or choose yourself

  • Drill down in Table or Pivot for derived column

    Hi All,
    I have a requirement like Top 5 products should show the product names and remaining should go to *'Others'*. I achieved it by using Rank function and case when.
    ex: case when rank(product) <=5 then product else 'Others' end
    Now the problem is, I am not getting the Drill option for this column. When I use product column without case when or case when on same column like
    case when product = 'xyz' then 'abc' else product end. In this case drill is working.
    Can anybody suggest me to get the drill on the derived columns.
    Thanks in advance

    A similar thread was recently talked about here:
    In OBIEE charts, how do you make drill downs work on custom formulas?
    With a calculated column, you need to make sure the source query and destination query have the EXACT same formula and the same name for the field. If it is not 100% identical, it may not work correctly. (I typically use the NAVIGATE function to get to the second query rather than the Drill function.)
    Now in some cases, if you try to create a second drill down query with more details in it, the original formula doesn't work the way you want it to. The calculated formulas have to make sense in both source query and destination query in order to work properly. If you have a ranking of the Top 5 Products in the source query, the destination query also has to have the same ranking of Top 5 products in order to work. If you add more fields into the destination query (e.g., adding on product attributes, or # of records associated with that product name etc.), then sometimes the ranking / aggregation in the destination doesn't add up the same way. This causes the system to think that the formulas are different and prevents the drill down.
    I managed to get around this by having a 3rd query in between the original summary view and the detailed data view. So the sequence would be (for example):
    - Dashboard based summary query (including the calculated ranked product names formula)
    - drill down into virtually identical query (add on one slight bit of difference here, for example adding on a second Product Name field ... not a calculated version, but the actual name). Create a drill down this time by clicking on the regular Product Name field (don't drill down on the custom formula)
    - final detailed drill-down query
    You can format this intermediary drill down query to explain to users that they need to click a second time.
    It's not ideal, but it should work. Hope this helps.
    Ted

  • Header1 size is required for Table Column header

    Hi Friends,
    I wanted to use Header1 size for Table column headers. Pls help me how to do.
    Now I am using external label with Header1 size to the table but labels are not aligned properly with the table columns.
    Regards,
    Lakshmi Prasad.

    Hi,
    For headers design property is not their so you cant change the font. Other option is to change the theme (Not tried personally).
    Regards
    Ayyapparaj

  • Change Date-Time format through derived column

    Hi,
    I have Date in MM-DD-YYYY Format & Want to convert it to
    YYYY-MM-DD format through derived column. Can anyone help with the expression required for the conversion.???
    Thanks.

    Adarsh,
    check the below modified one ..
    I have my OLEDB source query as :
    select convert(varchar(10),getdate(),101) as date_var
    My Expression used in the Derived Column part is :
    SUBSTRING((DT_WSTR,100)date_var,7,4) + "-" + SUBSTRING((DT_WSTR,100)date_var,1,2) + "-" + SUBSTRING((DT_WSTR,100)date_var,4,2)
    (It works irrespective of whther it is a DATE/DATETIME type or STRING type .. )
    Hope that helps!!
    Thanks,
    Jay
    <If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'>

  • Adding Rank for a Column in SSIS Derived Column

    H
    I want to add rank to a column in ssis in a derived column actually.
    Can u please tell how to add it and the syntax for adding it in a derived column.

    Thanks,
    Can you please give the script for the same.
    I am unable to write the script for my logic to implement in SSIS.
    I will be very thankful if some one could help me with it.
    Thanks in Advance.
    Sam thats too generic there would be several ways to solve one problem ... 
    can u tell us what is ur source [i mean table view THE DATA which records tuples you suspect is having duplicates ] 
    on what basis u decide duplicate ? and what row qualifies to go into destination ... for eg  say ur source is 
    select id,name, date from source_table  
    duplicacy could mean id and name being repeated multiple times and may be business rule is like pick up rec with latest date vale if thats the case go for source as : 
    select id, name,max(date) from sourcetable 
    group by id,name 
    if all the columns are repeating in your source table may be use DISTINCT ... 
    would be great if u give ur destination, source and business requirement ..
    if you have got primary key violations and any record qualifies then may be simply at destination component set Ignore failure property and ur job is done ...
    may be removing duplicate at source itself ... might solve ur problem 
    check out more on duplicates : http://blog.sqlauthority.com/2009/06/23/sql-server-2005-2008-delete-duplicate-rows/
    i hope u got the idea ... 
    Hope that helps ... Kunal

  • SSIS: Using CASE Statement Within A Derived Column Transformation Expression

    The following is my Data Flow:
    Ole DB Source > Copy Column > Derived Column >Ole DB Command
    My OLE DB Source has the following SQL command task:
    SELECT *
    FROM Repair R
    LEFT OUTER JOIN Vehicle V
    ON R.SN = V.SN
    AND R.Reg = V.Reg
    LEFT OUTER JOIN Product P
    ON R.PID = P.PID
    This yields a column of concern for me named PartNumber, which are represented by the following 2 formats:
    The following are my Copied Columns:
    Input Column = PartNumber
    Output Alias = Copy of PartNumber
    The following are my Derived Column expressions:
    Derived Column Name Derived Column Expression
    Name Replace 'PartNumber' LEFT(PartNumber,FINDSTRING(PartNumber,"-",1) - 1)
    Copy of Name Replace 'Copy of PartNumber' RIGHT([Copy of PartNumber],LEN([Copy of PartNumber]) - FINDSTRING([Copy of PartNumber],"-",1))
    So My PartNumber Column is Replaced with ######### of type
    string and the Copy of PartNumber column is replaced with
    #### of type int
    As I stated earlier PartNumber also is in the format of %-%-% which raises the following question:
    How can I replace PartNumber Column with NULL if in format of
    %-%-% and take the PartNumber and put it in new column named
    SubPart while keeping all the logic within SSIS objects?
    So in essence I want to do something like the following:
    PartNumber = CASE
    WHEN 'PartNumber' LIKE '%-%-%'
    THEN ABC = PartNumber AND PartNumber IS NULL
    END
    I have tried the case statement in a Derived Column expression and is not working. Would I add the
    CASE statement to the SQL command task in my OLE DB Source?
    I hope this question is concise for you.

    If it must be in SSIS, I would put a derived column stage earlier in the process to do my check for me. Then in the second derived column stage do the check against each output column (part, subpart, copy of part) to decide which way it goes
    PS Not sure if it's a 2012 function but SSIS has a function called TOKEN that will allow you to pull your subparts for you rather than the left/right you are doing

  • Convert SQL Query to Derived Column Expression

    I'm in the process of reworking some SSIS packages I inherited. A lot of these use Execute SQL Statement components to update certain fields in the tables once they've been loaded. I'd like to replace these individual UPDATE statements with Derived Column
    components.
    I've got 95% of them converted, except for a couple, one of which has me a bit perplexed and was hoping someone could provide some insight.
    Essentially, there is a column called POSTPERIOD which is a date in string format YYYYMM (i.e., 201503). The SQL update parses out the month piece and converts it to the month name and populates a column called POSTPERIOD_MONTH.
    Here is the SQL:
    select DateName(month , DateAdd(month, CONVERT(INT, SUBSTRING(POST_PERIOD,5,2)), 0 ) - 1 )
    I'd like to accomplish this using a Derived Column, but not sure how to go about doing this...
    If someone could point me in the right direction, it would be greatly appreciated!
    Thanks!
    A. M. Robinson

    Visakh:
    Thank you for the reply! I've tried your solution but am getting the following error(s):
    Warning 17 Validation warning. Populate STAGING_DIM_AP_DETAIL - RADIO: {ACAA99C4-272C-4641-BF44-B4D4409D1EFB}: The expression "(DT_STR,8,1252)((DT_I4)[SUBSTRING](#85,5,2) == 1 ? (DT_STR,8,1252)"January" : ((DT_I4)[SUBSTRING](#85,5,2)
    == 2 ? (DT_STR,8,1252)"February" : ((DT_I4)[SUBSTRING](#85,5,2) == 3 ? (DT_STR,8,1252)"March" : ((DT_I4)[SUBSTRING](#85,5,2) == 4 ? (DT_STR,8,1252)"April" : ((DT_I4)[SUBSTRING](#85,5,2) == 5 ? (DT_STR,8,1252)"May" :
    ((DT_I4)[SUBSTRING](#85,5,2) == 6 ? (DT_STR,8,1252)"June" : ((DT_I4)[SUBSTRING](#85,5,2) == 7 ? (DT_STR,8,1252)"July" : ((DT_I4)[SUBSTRING](#85,5,2) == 8 ? (DT_STR,8,1252)"August" : ((DT_I4)[SUBSTRING](#85,5,2) == 9 ? (DT_STR,8,1252)"September"
    : ((DT_I4)[SUBSTRING](#85,5,2) == 10 ? (DT_STR,8,1252)"October" : ((DT_I4)[SUBSTRING](#85,5,2) == 11 ? (DT_STR,8,1252)"November" : (DT_STR,8,1252)"December")))))))))))" will always result in a truncation of data. The expression
    contains a static truncation (the truncation of a fixed value).   Dimension Finance - Load STAGING_DIM_AP_DETAIL_DERIVED_COLUMNS.dtsx 0 0 
    This is the derived column expression I'm using:
    (DT_STR,8,1252) ((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 1? (DT_STR,8,1252) "January" : ((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 2 ? (DT_STR,8,1252) "February" : ((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 3 ? (DT_STR,8,1252) "March" :((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 4 ? (DT_STR,8,1252) "April":((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 5 ? (DT_STR,8,1252) "May" : ((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 6 ? (DT_STR,8,1252) "June" : ((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 7 ? (DT_STR,8,1252) "July" : ((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 8 ? (DT_STR,8,1252) "August":((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 9 ? (DT_STR,8,1252) "September":((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 10? (DT_STR,8,1252) "October": ((DT_I4)SUBSTRING([POST_PERIOD],5,2) == 11 ? (DT_STR,8,1252) "November" : (DT_STR,8,1252)"December")))))))))))
    Some info that might be of some help in the matter...the POST_PERIOD field is a VARCHAR(8), the POST_PERIOD_MONTH field is also a VARCHAR(8).
    There is a computed column Any help would be appreciated once again!!!
    A. M. Robinson

  • Derived Column : for Lookup type column with 'Allow Multiple Selection' : True in sharepoint list

    Hello,
    I have one column where field type is Lookup but 'Allow Multiple Selection' is true in SharePoint List.
    So, in this scenario data from the SharePoint list is being exported as below.
    1;#Red;#3;#Blue;#4;#Black;#5;#Green
    Now resultant text exported to SQL Table should be :
    1,3,4,5
    OR
    Red,Blue,Black,Green
    Either way it is fine. How can we get this using Derived Column and Data Conversion?
    I am able to do this for single occurrence using below expression.
    (DT_STR,100,1252)(SUBSTRING([BusinessUnit],FINDSTRING([BusinessUnit],"#",1)+1,LEN([BusinessUnit])-FINDSTRING([BusinessUnit],"#",1)))
    Please suggest.
    Thank you,
    Mittal.

    Your best bet would be to do this in sql using a string parsing udf as below
    http://visakhm.blogspot.com/2010/02/parsing-delimited-string.html
    You can make it into procedure and call it from oledb command task.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to find out the table column that is required for index

    hi all,
    i want to the column required for index in one schema.
    what are the ways to achieve the same.

    To know what columns to index you must, not should, but must, know your data, know how it will be used, and know how your WHERE clause filters will affect how the data is accessed.
    Building indexes based on some rule is a waste of CPU, disk i/o, and space.
    To build indexes that enhance rather than degrade a system requires research and the use of explain plan reports generated with DBMS_XPLAN.
    http://www.morganslibrary.org/library.html

  • Creating a header for rows/columns in cross-tab with syntax

    Hi,
    The issue is creating strings for rows or columns' headers. How can I create a formula field which contains more than one seperate string. Such as "aaa", "bbb" and "ccc" are headers and they should be in seperate columns. In short, they will behave like characteristics of one of my query's field but they are just headers of the columns.
    ..............aaa...bbb...ccc....
    row1.......x.......x........x.....
    row2.......y.......y........y.....
    Also there is another issue about the formulation again. Is there any operator that does the same job as " \n" which is used in C languages to break the line?
    before:
    aaabbb
    after:
    aaa
    bbb

    Hi Carl;
    Firstly, thanks for answering my question. To explain my problem there are two options ahead(for my first question); first one is writing down the actions step by step, the second one is posting an image file(jpeg etc) to visualize it. I think the first one will be enough. If not tell me
    Step 1- Create a cross-tab and right click and select cross-tab expert.
    Step 2- Click the button "New Formula" and write down any word(such as "Sales") between two -"- sign to make it string.Then save and close.
    Step 3- Drag and drop the created formula to "columns" section and fill the other necessary sections with your database's(such as xtreme.mdb which is famous for crystal users) fields.Don't forget to add another column value to "columns" section, since our formula has no link to database.
    Step 4- Then click OK to save the changes and lets preview the cross-tab.The result will have one top column and his child or children(that depends on your data). And this top column is behaving like a header not a field.
    Now turn the second step but write down a formula for 2 columns or more.For exmple "Sales" and "Profit".So the result will have 2 top columns and their child/children.
    My question is "what is the formula for 2 or more columns?"
    Also I couldn't get the answer for my second question. What is the meaning of expressions "\c" and ChrW(13)?
    Edited by: diabolus on Oct 30, 2009 9:39 AM

  • CDG-01141 ERROR: Module Component Table Usage ...  Table usage ... requires primary key column for referential integrity

    For some strange reason when I modified a form, (commented out some code in a when-window-activated trigger) I now get the following error.
    CDG-01141 ERROR: Module Component Table Usage GR1130A.CUSTOMER.GR_CUSTOMER.GC: Table usage GR_CUSTOMER requires primary key column for referential integrity
    I am sure this is not related to my change, but do not know what may have caused this or how to fix it.
    Anyone seen this error before? been able to fix it?
    Thanks!
    Windows 7
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0
    Designer Version 6.5.95.4.8

    You know that Developer/Designer 6i is not certified for Windows 7, right? Also, your version is not the latest one, so you can try to install the latest patch set first.
    >Table usage GR_CUSTOMER requires primary key column for referential integrity
    Check if there is a PK in the table definition (not in the database, but in Designer).

  • Derived column syntax help needed

    I am struggling getting the following case statement into the derived column format in SSIS
    CASE 
    WHEN SUBSTRING(REPLICATE('0', 9 - LEN(Data)) + CAST(Data AS VARCHAR(9)), 4, 6) IS NULL
    THEN 0
    ELSE RTRIM(SUBSTRING(REPLICATE('0', 9 - LEN(Data)) + CAST(Data AS VARCHAR(9)), 4, 6))
    END
    Here are examples for the data in Data
    row 1 - 1201303
    row 2 - 123456789
    row 3 - null
    row 4 - 12345678
    the first row result would be 201303
    row 2 result would be 456789
    row 3 result would be 0
    row 4 result would be 345678
    Andre Toerien

    I have a problem with the isnull, the isnull needs to be on the first 6 characters as well. 
    Maybe its best explained with the other similar fields
    ISNULL(LEFT((DT_STR,3,1252)CYCLE_YYYYMM,3)) ? "0" : LEFT((DT_STR,3,1252)CYCLE_YYYYMM,3)
    and 
    ISNULL(RIGHT((DT_STR,3,1252)CYCLE_YYYYMM,6)) ? "0" : RIGHT((DT_STR,6,1252)CYCLE_YYYYMM,6)
    We are trying to keep the coding similar on all our fields even if its a but redundant, we moved over from an Adabas system, and in the last example there are actuallt cases with the  first three characters being seen as nulls, if I understand correctly
    the fields in Adabas are right aligned which causes this, so I need to cater for the difference between a true null where I expect a null value to be returned and one where a substring on a left(field,6) return a null which then as to return a 0..
    ISNULL(LEFT((DT_STR,3,1252)CYCLE_YYYYMM,3)) ? "0" : LEFT((DT_STR,3,1252)CYCLE_YYYYMM,3)---this one is actually a substring(field,1,3) and the one below is a substring(field,4,6)
    ISNULL(RIGHT((DT_STR,3,1252)CYCLE_YYYYMM,6)) ? "0" : RIGHT((DT_STR,6,1252)CYCLE_YYYYMM,6)
    some of the vause in sql are actually 0 for the 1,3 and 201302 for the 4,6, same field
    Hope this makes sense, i actually tested this and the data actually is like that. I also need an example of how to handle the second example 
    ISNULL(RIGHT((DT_STR,3,1252)CYCLE_YYYYMM,6)) ? "0" : RIGHT((DT_STR,6,1252)CYCLE_YYYYMM,6) - this is of course the substring 4,6 field
    I am serious;y considering leaving the derived column if I cannot get this to work, have been struggling with this for a few days
    Andre Toerien

  • Avoiding derived columns for mapping purposes only

    Hi.  In 2012 has there been any advancement that would alleviate us from adding a derived column simply for the purpose of mapping an existing var or param to an oledb output column? 

    Hi DB042189,
    According to your description, what you would like to do is directly mapping a variable or parameter to an Output column of a Data Flow Task control without adding a new column through the Derived Column transform. If so, this is not supported in SSIS 2012
    currently. I would suggest you submitting a wish at
    https://connect.microsoft.com/sql.
    Connect site is a connection point between you and Microsoft, and ultimately the larger community. Your feedback enables Microsoft to make software and services the best that they can be, and you can learn about and contribute to exciting projects.
    Regards,
    Mike Yin
    TechNet Community Support

  • What is the expression syntax to make the visibility of a column hidden in a Tablix?

    So if my Parameter value is...
    MCCL, MCMA, MCPL, MCPR, MCRE, MCSE, MCSN, MCVA, MCCL, MCEP, MCMA, MCRE out of 43 possible choices, what is the expression syntax to hide my tablix column based on my parameter value?
    =iif(instr(Join(Parameters!ColumnVisibility.Value,","),"MCCL","MCMA","MCPL"...)>0,false,true)
    Just not sure of the syntax...or do I have to qualify each one???
    = IIf(Parameter!PF1.Value = "MCCL" OR Parameter!PF1.Value = "MCMA"..., TRUE, FALSE)

    Hi ITBobbyP,
    Per my understanding that you have create multiple values parameter "ColumnVisibility" based on the fields LineofBusiness and the fields LineofBusiness have the n to 1 relationship with the BusinessUnit like below(Sample Data):
    When you select values from the dropdown list which only include the "FM" or "MC", the column "HCFNumber" will show or it will hide, right?
    If so, If you have two many values in the lineofBusiness mapped of the BusinessUnit, you can create an new cascading parameter "BusinessUnit" based on the BusinessUnit field like below:
    select distinct a.BusinessUnit from (select 'MCCL' lineofBusiness, 'MC' BusinessUnit ,11 HCFANumber
    union
    select 'MCCS' lineofBusiness, 'MC' BusinessUnit ,11 HCFANumber
    union
    select 'COLG' lineofBusiness, 'CO' BusinessUnit ,11 HCFANumber
    union
    select 'COSM' lineofBusiness, 'CO' BusinessUnit ,22 HCFANumber
    union
    select 'FMMS' lineofBusiness, 'FM' BusinessUnit ,33 HCFANumber
    union
    select 'FMCG' lineofBusiness, 'FM' BusinessUnit ,44 HCFANumber)a
    where lineofBusiness in (@LineofBusiness)
    Add another filter in the (@BusinessUnit) and use expression below on the column visibility:
    =IIF(Join(Parameters!BusinessUnit.Value,",")="FM" or Join(Parameters!BusinessUnit.Value,",")="MC" or Join(Parameters!BusinessUnit.Value,",")="FM,MC" , false,true)
    Preview like below:
    If you still have any problem, please try to provide more details information about the expect result you want to get based on the show/hide.
    Regards,
    Vicky Liu
    Vicky Liu
    TechNet Community Support

Maybe you are looking for