troubleshooting Question

Like Statement

Avatar of pepps11976
pepps11976 asked on
Microsoft SQL Server 2008
7 Comments1 Solution255 ViewsLast Modified:
Hi i have the following view
SELECT     TOP (100) PERCENT CAST(dbo.itran.it_exdate AS datetime) AS Month, dbo.ihead.ih_sorder AS Sales_Order, dbo.ihead.ih_doc, dbo.ihead.ih_sprojid AS Opportunity_No, 
                      dbo.ihead.ih_custref AS Customer_Reference, dbo.itran.it_stock AS Stock_Reference, dbo.itran.it_quan AS Quantity, dbo.ihead.ih_account AS Account, 
                      dbo.ihead.ih_name AS Name, dbo.itran.it_exdate AS Customer_Date, CAST(dbo.itran.it_due AS datetime) AS Our_Date, CAST(DATEDIFF(dd, dbo.itran.it_exdate, 
                      dbo.itran.it_due) AS varchar(20)) AS Date_Difference, CAST(DATEDIFF(dd, dbo.itran.it_exdate, { fn NOW() }) AS varchar(20)) AS Past_Due, 
                      dbo.itran.it_doc AS [Document], dbo.ihead.ih_quotat AS Quotation, dbo.ihead.ih_proform AS Proforma, dbo.itran.it_anal AS Anaylysis_Code, 
                      CAST(dbo.ihead.ih_orddate AS datetime) AS Order_Date, CASE WHEN dbo.itran.it_dtedelv = '1899-12-30' THEN NULL ELSE dbo.itran.it_dtedelv END AS Delivery_Date, 
                      CASE WHEN dbo.fnGetBusinessDays(dbo.itran.it_dtedelv, it_exdate) BETWEEN 0 AND 5 THEN 'Pass' ELSE NULL END AS Passed_Delivery, 
                      CASE WHEN dbo.itran.it_dtedelv = '1899-12-30' OR
                      dbo.fnGetBusinessDays(dbo.itran.it_dtedelv, it_exdate) BETWEEN 0 AND 5 THEN NULLIF (' ', ' ') ELSE 'Fail' END AS Failed_Delivery, 
                      dbo.fnGetBusinessDays(dbo.itran.it_dtedelv, dbo.itran.it_exdate) AS Delivery_Days, DATEPART(mm, dbo.itran.it_exdate) AS Month_No
FROM         dbo.ihead LEFT OUTER JOIN
                      dbo.itran ON dbo.ihead.ih_doc = dbo.itran.it_doc
WHERE     (dbo.itran.it_status = 'A') AND (dbo.ihead.ih_orddate >= '2009-01-01') AND (dbo.itran.it_anal NOT LIKE '%zz%') AND (dbo.itran.it_anal NOT LIKE '%LIN%') AND 
                      (DATEPART(yyyy, dbo.itran.it_exdate) = DATEPART(yyyy, GETDATE()))

i am trying to add to the end of it

where ih_name = 'Selex Galileo Limited' or ih_name like '%Thales%'

however i am being returned thousends of rows instead of expecting 84 rows. the where statement does not seem to be taking into account the datepart that i have before i try to narrow it down by names.

can anybody help?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros