6 Replies Latest reply: Jan 31, 2012 4:58 PM by David Nelson RSS

    Multiple load - where statements?

      I've successfully filtered out values from one table with this statement:

       

      SQL SELECT *
      FROM "Request_report".dbo."V_MSR" where app_id=3 or app_id=22 or app_id=63;
      

       

      Now I need to filter out another value upon load, though:

       

      SQL SELECT *
      FROM "Request_report".dbo."V_MSR" where status_id != 0;
      

       

      By themselves, these statements work fine, but I cannot figure out how to do both of them upon load. Is there something I'm missing? Is there another way to do this? I'm not looking for bookmarks, either, I'm hoping for script executed upon load if possible. If this isn't an option, I understand.

        • Multiple load - where statements?
          Edgar Kech

          sounds you're looking for something like this?

           

          load

               *

          ;

          SQL SELECT *
          FROM "Request_report".dbo."V_MSR" where (app_id=3 or app_id=22 or app_id=63) and status_id != 0

          ;

           

          combining where-conditions in SQL is straight-forward if you know what's your AND and OR - in this case you have to use the parenthesis...

           

          Greetings,

          Edgar

            • Multiple load - where statements?

              That is exactly what I needed, I wasn't using the parantheses. I'm still trying to get a hang of Qlikview syntax.

              • Re: Multiple load - where statements?

                I didn't want to make a near-duplicate post concerning this, hence the "un-corrected" response, no offense...

                 

                Now I have to filter out a status_id of "11" on load, too, so how would that go? This code doesn't work:

                 

                SQL SELECT *
                FROM "Request_report".dbo."V_MSR" where (app_id=3 or app_id=22 or app_id=63) and (status_id!=11 or status_id!=0);
                


                Once again I'm stumped with the correct syntax needed.

                  • Re: Multiple load - where statements?
                    Miguel Angel Baeyens de Arce

                    Hi,

                     

                    Do you need to load when both app_id and status_id are true? Is there a chance that you need to use OR instead of AND in the WHERE clause:

                     

                    Data:
                    
                    LOAD *;
                    
                    SQL SELECT *
                    FROM "Request_report".dbo."V_MSR" 
                    where (app_id=3 or app_id=22 or app_id=63) 
                    or (status_id!=11 or status_id!=0);
                    

                     

                    This will retrieve all records where either the first parenthesis or the second (or both) is true.

                     

                    Hope that helps.

                     

                    Miguel

                      • Re: Multiple load - where statements?

                        To specify what I'm trying to achieve:

                         

                        I have two fields (app_id & status_id). They are numeric values. I would like to load only three values from app_id (3, 22, 63) and would like to load all values but 0 and 11 in status_id. Both need to be true, not one or the other.

                         

                        I've tried Miguel's code but unfortunately that didn't work. I've also tried the following:

                         

                        SQL SELECT *
                        FROM "Request_report".dbo."V_MSR" 
                        where (app_id=3 or app_id=22 or app_id=63) or (status_id<>11 or status_id<>0);
                        

                         

                        Is this possible?

                  • Re: Multiple load - where statements?

                    Figured it out with this code:

                     

                     
                    
                    SQL SELECT *
                    FROM "Request_report".dbo."V_MSR" 
                    where (app_id=3 or app_id=22 or app_id=63) and (status_id != 0 and status_id != 11);
                    

                     

                    Thanks for all the help everyone!