Select where case

I am trying to build the query below to throw in SSRS.  I have a multivalued parameter called @category.  When the value of
USCATVLS_2 is blank I want to still have the option to pull it in my report.  Below is what I have started that doesn't work.  any ideas?
select
*fromiv00101
i
where
i.USCATVLS_2
=(casewheni.uscatvls_2
=''then'NA'elsein(@category)end)
http://www.isolutionspartners.com/

My parameter is multivalue, so it should look something like the syntax below, but the syntax doesn't check out.  Any ideas?
select
*fromiv00101
i
where
i.uscatvls_2
=CASEWHENi.uscatvls_2
=''THEN'NA'ELSEin(@category)END
http://www.isolutionspartners.com/

Similar Messages

  • SQL query problem - select max (case... aggregate function)

    Hi,
    I have a problem with below sql query, it gives me problem/error message 'ORA-00937: not a single-group group function', why?
    select sag.afdeling, sag.sagsnr, to_char(sag.start_dato, 'yyyy-mm-dd'), sag.stat, BOGF_TRANS.TRANSTYPE,
    max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
    max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
    max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
    from sag
    join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
    where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
    group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
    If I exclude (columns) as below it give me correct summations (max (case... sum(...)) but then I miss some important info that I need
    select
    max (case when BOGF_TRANS.TRANSTYPE = 'K' then sum(bogf_trans.belobdkk) end) + -- as "TRANSTYPE K",
    max (case when BOGF_TRANS.TRANSTYPE = 'D' then sum(bogf_trans.belobdkk) end) as "TRANSTYPE K & D",
    max (case when BOGF_TRANS.TRANSTYPE = 'S' then sum(bogf_trans.belobdkk) end) as "SUM TRANSTYPE S"
    from sag
    join bogf_trans on sag.selskab = bogf_trans.selskab and sag.sagsnr = bogf_trans.sagsnr and sag.afdeling = bogf_trans.afdeling
    where SAG.SELSKAB=37 and SAG.AFDELING = 'SUS' AND SAG.SAGSNR = 10876
    group by sag.afdeling, sag.sagsnr, sag.start_dato, sag.stat, BOGF_TRANS.TRANSTYPE
    Any ideas?

    Moved to more sutable forum, sorry.

  • How do you keep the order using SELECT WHERE IN()?

    Hi,
    Is there a way to keep the order when using SELECT WHERE IN()? For example, using the following query:
    SELECT id FROM data_table WHERE id IN('56','55','54','1','7');
    The results will come back using the default order by id. 1,7,54,55,56
    When I want to keep the order used in the IN: 56,55,54,1,7
    Is there a quick way to do this in mySQL or will I be forced to order it after in code.
    Thanks

    797836 wrote:
    Hi,
    Is there a way to keep the order when using SELECT WHERE IN()? For example, using the following query:
    SELECT id FROM data_table WHERE id IN('56','55','54','1','7');
    The results will come back using the default order by id. 1,7,54,55,56In case the order by docs and comments weren't clear on this point, there is no default order and they may come back in a different order. Usually after you've tested it to exhaustion to prove otherwise, then put it in production.
    >
    When I want to keep the order used in the IN: 56,55,54,1,7
    Is there a quick way to do this in mySQL or will I be forced to order it after in code.
    ThanksUsing the in list allows oracle to have other possible data access paths than simply running the query 5 times. If for whatever reason you don't want to order the results after they come back, it may be worth your while to just run the five queries serially in the order you want, using bind variables and so having identical queries. That may seem silly on its face, but then again, we don't know the real requirements, what else is going on, if this is simplified from the real code or whether there will always be 5.

  • Where case when query not running at all in 11.2.0.3

    Hi,
    I have a query that was running fine till the time we were in 11.1.0.7. Last month, we had a migration to 11.2.0.3, and the query has stopped running since then. It runs indefinitely, and finally I have to kill it. However, until 11.1.0.7, I had absolutely no problems with it. Not sure what changed in 11.2.0.3 that causes it to never give me a result. The query is as below:
    SELECT T1.NAME,T2.AGE,T2.level, T2.AMT,
    FROM table1 T1, table2 T2
    WHERE (CASE WHEN
    (T1.name = 'Peter' AND SUBSTR(T1.desc,1,15)=SUBSTR(T2.description,1,15))
    THEN 1
    ELSE 0
    END)=1;
    Please advise!
    Thanks in advance.

    Hi,
    CrazyAnie wrote:
    Hi,
    I have a query that was running fine till the time we were in 11.1.0.7. Last month, we had a migration to 11.2.0.3, and the query has stopped running since then. It runs indefinitely, and finally I have to kill it. However, until 11.1.0.7, I had absolutely no problems with it. Not sure what changed in 11.2.0.3 that causes it to never give me a result. The query is as below:
    SELECT T1.NAME,T2.AGE,T2.level, T2.AMT,
    FROM table1 T1, table2 T2
    WHERE (CASE WHEN
    (T1.name = 'Peter' AND SUBSTR(T1.desc,1,15)=SUBSTR(T2.description,1,15))
    THEN 1
    ELSE 0
    END)=1;
    Please advise!I'm surprised it runs in any version. You have a comma right before the keyword FROM. If you were not getting a compile-time error, that was a bug in 11.1.0.7 that they fixed by 11.2.0.3.
    It's still strange that the query runs for a long time. I would expect it to give you an error when you tried to compile it. Is there any chance that what you posted is not what you're actually running?
    Also, LEVEL, NAME and DESC are not good column names. How Oracle reacts to using keywords like that as column names can vary from version to version. If a word is in v$reserved_words.keyword, then it's best to avoid using it as a column (or table, or variable, or schema) name.
    Edited by: Frank Kulash on Nov 21, 2012 1:33 PM
    By the way, that WHERE clause is a lot more complicated than it needs to be. Why not use
    WHERE      t1.name = 'Peter'
    AND      SUBSTR ( t1."DESC"     -- If you must use DESC, double-quote it
                , 1
                , 15
                ) = SUBSTR ( t2.description
                               , 1
                     , 15
                     )? Always think carefully before using CASE in a WHERE (or HAVING, or START WITH, or CONNECT BY) clause.

  • Select where date current_date

    Hi, all
    I just tried to play with that select where I need to pick up records with TRADEDATE < 'CURRENT-DATE' and really impressed how intuituve Oracle is.
    tradedate date;
    SELECT * FROM TRADEMIX WHERE TRADEDATE <= (SELECT CURRENT_DATE FROM DUAL); works just fine, I see that even Month displayed as char 'SEP' treated in right collating order. Wow !!!
    So looks I don't need to do anything special ? It's my first experience with Oracle, so I just want to confirm that it's really the case.
    Also what will be the best way to do select only for TRADEDATE = ' 2010' (all records for give year)? Do I need to do any to_char for that? Not sure about correct syntax, all sample in texbook noted the whole date string 'DD-MON-YY'.
    Thanks
    Trent

    trento wrote:
    Hi, all
    I just tried to play with that select where I need to pick up records with TRADEDATE < 'CURRENT-DATE' and really impressed how intuituve Oracle is.
    tradedate date;
    SELECT * FROM TRADEMIX WHERE TRADEDATE <= (SELECT CURRENT_DATE FROM DUAL); works just fine, I see that even Month displayed as char 'SEP' treated in right collating order. Wow !!!
    So looks I don't need to do anything special ? It's my first experience with Oracle, so I just want to confirm that it's really the case.
    Also what will be the best way to do select only for TRADEDATE = ' 2010' (all records for give year)? Do I need to do any to_char for that? Not sure about correct syntax, all sample in texbook noted the whole date string 'DD-MON-YY'.
    Thanks
    TrentYou have some other examples for dealing with a just the year component of dates, but let me also point out a simpler form of what you have here:
    select * from trademix where tradedate <= sysdate;Just reference SYSDATE. No need to do a subselect against dual.
    And keep these things in mind:
    Oracle always stores DATE data in its internal format. That format includes both date and time.
    NSL_DATE_FORMAT, and the TO_DATE and TO_CHAR functions only deal with the presentation of the date.
    Play with this:
    alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
    select sysdate from dual;
    alter session set nls_date_format='dd-mon-yyyy hh24:mi:ss';
    select sysdate from dual;
    alter session set nls_date_format='yyyy-Mon-dd hh24:mi:ss';
    select sysdate from dual;
    alter session set nls_date_format='yyyy-MON-dd hh24:mi:ss';
    select sysdate from dual;
    alter session set nls_date_format='mm-dd-yyyy';
    select sysdate from dual;
    select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
    select to_char(sysdate,'dd-mon-yyyy hh24:mi:ss') from dual;
    select to_char(sysdate,'yyyy-Mon-dd hh24:mi:ss') from dual;Also keep firmly in mind that a character string is just that - a character string. No matter how much it may look like a date to you. Your keyboard is only capable of generating character strings. Your monitor is only capable of displaying character strings.

  • How do I get iPhoto on new iPad to load all Facebook albums to select where to upload?

    How do I get iPhoto on new iPad to load all Facebook albums to select where to upload?
    Besides 'new album' , 'wall photos', or 'iPhoto Uploads' ... it only shows 24 pre-existing albums to choose. I need to see the other 50, 60, etc albums I have.
    I've also noticed that iPhoto fails to load to certain albums with some 'Domin Exception' error of some kind (not sure the exact message).

    You need to make the new Mac iTunes library your syncing library. iTunes on the Mac sees your iPad as a new device because you have never synced with this computer before. You can make the Mac your syncing computer by following the instructions in this user tip. You will be able to transfer the purchased music on the iPad into iTunes when you follow this procedure.
    Syncing to a new computer.
    https://discussions.apple.com/docs/DOC-3141

  • Select where Ken Burns into?

    On Windows Movie Maker, I could select the location where the KBE would zoom into. As far as I can tell, iMovie does it automagically. Is there a way to select where to apply the KBE (not on/off or zoom in/out)?
    Thanks

    Also, click on the rectangle to toggle between the red rectangle and the green rectangle.

  • What is the problem with this select include case

    i try to determine according to salary here is the sentence
    Select empno ,ename, sal, (case sal when sal<4000 then .05*sal
    when sal>4000 then .1*sal
    else 0 end) as "Required"
    from emp;
    it give me missing keyword erro
    thanks

    Hi,
    Try this:
    SQL> SELECT
      2  (CASE
      3      WHEN SALARY<4000 THEN .05*SALARY
      4      WHEN SALARY>4000 THEN .1*SALARY
      5      ELSE 0
      6   END
      7   ) REQUIRED
      8   FROM EMP;
      REQUIRED
           440
           650
          1000
           700
           900
           600
           480
           480
          1400
          1350
          1200
      REQUIRED
          1100
           800
           820
           790
           650
          1200
           900
           820
           770
          2400
    21 rows selected.
    SQL>
    Note: Please post your error message.
    Cheers,

  • ERROR message (iDVD) 'no video tracks selected'  where is 'SHARED'

    (I think everyone's asleep on the iDVD boards, so I've taken the liberties of posting here also, sorry.... ssshhhhhhh....)
    My first time using iDVD (it's 5.0) --
    Exported sequence from fcp as QT.....
    Dropped into into 'drop zone' hit 'burn', and get "no video track defined"
    I searched this forum (iDVD) and it seems I need to tweek "shared" setting.... since I made the sequence in fcp (not iMovie), where is this 'shared' menu?
    Very perplexing...
    Thanks.
    Mark

    Here'w what Ken says from his article detailing iDVD:
    Once you have set all your markers, set an in and out point on your Timeline, File Menu > Export. From FCP 4.5 and FCE 2, select QuickTime Movie (not 'Using QuickTime Conversion').
    There is an option in the Save box, "Make Self contained". If you uncheck this box the movie that is generated will consist of pointers to your media. The export process will happen quickly and the resulting file will be small in size. This is a good choice if you will be using iDVD on the same Mac as your editing application. If you chose to "Make Self contained" the resulting movie will contain all of the media, it will take longer to export and the file size can be quite large, (about 22 gigs for a 100 minute movie). If you will be moving to a different Mac to work on iDVD then you'll need to have your movie be self contained. In either case, leave 'Recompress All Frames' unchecked.

  • SQL - Select Help - Case When? Return Value from Second Table?

    Hi - next to folks on this board I am probably somewhere between a Beginner and an Intermediate SQL user.
    Ive been using a case when statement in plsql to find "all those who's status in any program was cancelled during a specific time, but have become or are still active in a second program"
    So, Im effectively trying to return a value from a second table in a case when, but its not liking anthing other than a declared text like 'Yes' or 'No'.
    Here is the select statement - is there another way to do this where I can get the results I need?
    case when pp.party_id in (select pp1.party_id  -- Cancelled clients Active in another program
                                       from asa.program_participation          pp1,
                                            asa.curr_prog_participation_status cpps1
                                      where pp1.program_participation_id = cpps1.program_participation_id
                                        and pp1.party_id = pp.party_id
                                        and cpps1.code_value = 'ACT')
                then 'Yes' else 'No' end  as Active_in_Other_Prg
    So - in place of 'Yes' i basically want the program that they are active in or pp1.program_id, else Null
    It is possible that the client can be active in more than one program as well.
    Any assistance is greatly appreciated, i explored with if's and decodes but I cant get anything to work.
    Batesey

    Sounds like an outer join. See ora doc: Joins
    select p.*
    ,      q.party_id
    ,      q.program_id
    from   table_with_party_id p
    ,    ( select pp1.party_id  -- Cancelled clients Active in another program
           ,      pp1.program_id
           from   asa.program_participation          pp1,
                  asa.curr_prog_participation_status cpps1
           where  pp1.program_participation_id = cpps1.program_participation_id
           and    pp1.party_id = pp.party_id
           and    cpps1.code_value = 'ACT') q
    where p.party_id = q.party_id ( +)
    Note: In the example above there shoudn't be a space between the ( and +), but the forum software automagically converts this to
    The outer join will link show all records from the p table and only records from q if the party_id matches, ie q.party_id and q.program_id  will be null if there is no match.
    edit: added program_id

  • How to select a case sensitive value in SQL with C#

    Hello,
    I have an application that at the begining a user will login with a user name and password which is stored in the database. The SQL statement is as follows:
    "SELECT id_employee FROM employee WHERE employee_number='" + txtUserName.Text + "' AND passWord='" + txtPassword.Text + "'";
    For testing purposes I have set the password to the word test.   The problem is, if the user enters in TEST or TeSt or TESt  it will grant them access. How do I set it to force the correct case?
    I am using SQL 2005 for the database.
    Thanks!
    ~zero

    You can also set Collation while comparing strings:
    "SELECT id_employee FROM employee WHERE employee_number='" + txtUserName.Text + "' COLLATE Latin1_General_CS_AS AND passWord='" + txtPassword.Text + "'  COLLATE Latin1_General_CS_AS";
    All comments about not doing this type of quering using command string, instead of command with parameters, they are apsolutely right.
    Nevertheless i will have only username as a parameter in the command and password will be return value from procedure. I will check for equality of entered password and returned one from command in C# code, and C# is case sensitive. There is a good security model implemented for password in AdventureWorks sample database for SQL Server 2005, in table Person.Contact.
    That model use two fields for password, PasswordHash and PasswordSalt. PasswordSalt is randomly generated hash when password is modified and with that salt, password string is encrypted, which produce PasswordHash. So when you want to authenticate a user, execute a command that will return a row(PasswordHash and PasswordSalt) for entered username, and in application you will encrypt entered username with PasswordSalt. If generated string is equal with the one returned PasswordHash, then you have a valid login. If nothing is returned from command or they are not equal, you have invalid login.

  • SELECT in CASE

    CASE v_res_bl
    WHEN 'A' THEN RETURN pkg_a.get_id(c_yes,p_id);
    WHEN 'B' THEN RETURN pkg_a.get_id(c_no,p_id);
    WHEN 'C' THEN
    select a
    INTO v_res_bl
    from table
    join 1
    join 2
    join 3
    where 1
    and 2;
    select a
    INTO v_res_bl
    from table
    join 1
    join 2
    join 3
    where 2
    and 2;
    CASE v_res_bl1
    WHEN 'A' THEN RETURN pkg_a.get_id(c_yes,p_id);
    WHEN 'B' THEN RETURN pkg_a.get_id(c_no,p_id);
    END CASE;
    END CASE;
    Can I use this ? Is it correct?

    Well, first you CASE v_res_bl, and in case of 'C' you select into the same variable and CASE another one (v_res_bl1). Is that the logic you want? At least, it is confusing.
    Perhaps an IF..ELSIF construction would be more readable and easier to debug or modify, if necessary.
    Furthermore, try to use exactly one return command in a function. Assign the desired values to a variable and return that value at the end of the function. Again, this will help in terms of debugging and modifying the function in the future and will be more structured and easier to understand for other developers.
    if v_res_bl = 'A' then
       v_ret := xy;
    elsif v_res_bl = 'B' then
       v_ret := yz;
    elsif v_res_bl = 'C' then
       select...
       select...
       if v_res_bl1 /* please give this another name! */ = 'A' then
          v_ret := ab;
       elsif v_res_bl1 = 'B' then
          v_ret := bc;
       end if;
    end if;
    return v_ret;Just a proposal...
    Regards,
    Gerd

  • How to "select" with case ignored???

    Hi everyone, I need to select a field from table, but the data might be written in low case or upper case, even mixed case. for example, i want to select "test" or "TEST" or "Test" in column, what should I modify in my sql "select column1 from tableA where column1 = 'test'" ???
    Thanks in advance

    How about ignoring punctuation marks etc. E.g. search for ABC yields A.B.C. , A-B-C, A B C, and other combinations if present. Does a tool which does something similar exist?

  • Select query case insensitive for data type VARG

    Hi Experts,
    I am having trouble in retrieving the results from a table using select query.
    I have a table (Users) as below
    Name (VARG)        Number(INTEGER)
    Murthy             0001
    murthy             0002
    when I am querying the table with select query as -
    select * from Users where Name = 'Murthy'
    this query is returning only one record which matches with capital letter of 'M', though both the record names are same.
    I have seen in IBM forum to make the select query as case insensitive using the UPPER key word, I have tried this as below -
    select * from Users where UPPER(Name) = 'MURTHY'
    But this query is not working in my case...
    My DB2 version is 8.1.5
    Can any one please help in fixing this problem...
    Thanks in Advance,
    Murthy

    Hi Murthy,
    your query is the right to one to select both records. I don't see why it doesn't work.
    Are you sure you posted the query that you have executed ?
    What is the result of this query ?
    But i don't really know how an VARG (Varying-length graphic string) will work. It could be that the UPPER-Function will work in another way as it works on VARCHAR.
    regards
    Kay

  • Select, where column = alias

    Hi,
    is it possible to use c.LgDatM in where clause?
    I would like to tell him to give me values only for months from column LgDatM.
    My where clause:
    WHERE MONTH(LogDate) BETWEEN 3 and 4)
    and the code
    SELECT c.LgDatM, a.EmpCount, b.LgDat FROM
    (SELECT MONTH(LogDate) as LgDatM FROM [Prometheus].[dbo].[tblMain])c,
    (SELECT COUNT(DISTINCT Enumber) as EmpCount FROM [Prometheus].[dbo].[tblMain]
    WHERE MONTH(LogDate) BETWEEN 3 and 4)a,
    (SELECT COUNT(DISTINCT LogDate) as LgDat FROM [Prometheus].[dbo].[tblMain]
    WHERE MONTH(LogDate) BETWEEN 3 and 4)b
    GROUP BY c.LgDatM, a.EmpCount, B.LgDat
    GO
    Then you very much
    Mathh

    SELECT Month(logdate)      AS lgdatm, 
           Count(DISTINCT CASE 
                            WHEN Month(logdate) BETWEEN 3 AND 4 THEN enumber 
                            ELSE NULL 
                          END) AS EmpCount, 
           Count(DISTINCT CASE 
                            WHEN Month(logdate) BETWEEN 3 AND 4 THEN logdate 
                            ELSE NULL 
                          END) lgdat 
    FROM   [tblmain] 
    GROUP  BY Month(logdate) 

Maybe you are looking for

  • Problem running a report in forms.

    Hello! I am having a problem with running a report in a form. I have installed on my computer Oracle developer suite 10g, weblogic, oracle database 11g. Now i have a main form in witch runs froms and reports. The forms and reports had run well on ora

  • Error while deploying application with TablePopinToggleCell UI element

    Hi I am using NWDS 7.0 and have developed an application with a Table that uses TablePopinToggleCell. When I deploy this on a server (NW2004s), it gives me the following error: java.lang.NoClassDefFoundError: com.sap.tc.webdynpro.clientserver.uielib.

  • Keeping my iTunes Libraries in Sync

    My wife and I share a single iTunes library from separate accounts on an iMac (actually I have two accounts - one for me and one for work, for a total of 3). The song files are on an external HD, the iTunes Library and iTunes Music Library.xml files

  • Unable to open Adobe Acrobat Pro after CS4 Design Premium install

    I recently purchased Adobe CS4 Design Premium. I attempted to install it Sunday, and it completed with an indication of success. I then tried to open all my applications to make sure everything went well, and Acrobat keeps coming up with the followin

  • Installer.app rights

    Is it normal for Installer.app located in /System/Library/Core Services, when it asks for your admin password, to ask for the right system.install.root.user ?