5

& lt; & gt; not equal to function does not work correctly to filter reco...

 3 years ago
source link: https://www.codesd.com/item/not-equal-to-function-does-not-work-correctly-to-filter-records-in-sql-server.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

& lt; & gt; not equal to function does not work correctly to filter records in SQL Server

advertisements

I have a business requirement where I need to alter the SSRS report based on some additional filtering. I have a field name as ProductShortName where they don't want records where Product name is 'BLOC', 'Small Business Visa', Product name starting with 'WOW' and Product name ending with 'Review'.

This is the original where condition:

       WHERE ( A.AppDetailSavePointID = 0) AND (B.QueueID = 1)
              AND (A.DecisionStatusName <> N'Cancelled')
              AND (A.DecisionStatusName <> N'Withdrawn')
              OR  (A.AppDetailSavePointID = 0)
              AND  ((B.QueueID = - 25) OR (B.QueueID = - 80))
              AND (A.DecisionStatusName <> N'Cancelled')
              AND (A.DecisionStatusName <> N'Withdrawn')
              OR  (A.AppDetailSavePointID = 0)
              AND (A.DecisionStatusName <> N'Cancelled')
              AND (A.DecisionStatusName <> N'Withdrawn')
              AND (LEFT(C.QueueName, 2) = 'LC')

I added additional filtering to meet the criteria:

 WHERE (A.AppDetailSavePointID = 0)
        AND ((A.ProductShortName <> 'BLOC')
        AND (A.ProductShortName <> 'Small Business Visa')
        AND NOT (A.ProductShortName LIKE 'WOW%')
        AND NOT (A.ProductShortName LIKE '%Review'))
        AND (B.QueueID = 1)
        AND (A.DecisionStatusName <> N'Cancelled')
        AND (A.DecisionStatusName <> N'Withdrawn')
        OR (A.AppDetailSavePointID = 0)
        AND ((B.QueueID = - 25) OR (B.QueueID = - 80))
        AND (A.DecisionStatusName <> N'Cancelled')
        AND (A.DecisionStatusName <> N'Withdrawn')
        AND ((A.ProductShortName <> 'BLOC')
        AND (A.ProductShortName <> 'Small Business Visa')
        AND NOT (A.ProductShortName LIKE 'WOW%')
        AND NOT (A.ProductShortName LIKE '%Review'))
        AND (A.AppDetailSavePointID = 0)
        AND (A.DecisionStatusName <> N'Cancelled')
        AND (A.DecisionStatusName <> N'Withdrawn')
        AND (LEFT(C.QueueName, 2) = 'LC')
        AND ((A.ProductShortName <> 'BLOC')
        AND (A.ProductShortName <> 'Small Business Visa')
        AND NOT (A.ProductShortName LIKE 'WOW%')
        AND NOT (A.ProductShortName LIKE '%Review'))

While this removes the products but it additionally removes few more products. I don't understand how? Can anyone please suggest an appropriate where condition?


It may be easier to read if you deassociate the universal predicates.

(X and Y) or (X and Z) == X and (Y or Z)

This yields:

WHERE (A.ProductShortName NOT LIKE 'WOW%')
  AND (A.ProductShortName NOT LIKE '%Review')
  AND (A.ProductShortName <> 'Small Business Visa')
  AND (A.DecisionStatusName <> N'Cancelled')
  AND (A.DecisionStatusName <> N'Withdrawn')
  AND (A.AppDetailSavePointID = 0)
  AND (   QueueID = 1
       OR QueueID = -25
       OR QueueID = -80
       OR LEFT(C.QueueName, 2) = 'LC'
      )


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK