Advertisement

04.28.2008 at 07:57AM PDT, ID: 23358935
[x]
Attachment Details

Case Statement with Greater Than

Asked by timoteoga in MS SQL Server

Tags: , , ,

I'm a rookie as CASE statements and need some help.  This query worked fine until I added the one CASE statement, and now, I can't get it to run.  I keep ketting the following message:

Server: Msg 170, Level 15, State 1, Line 4
Line 4: Incorrect syntax near '>'.

What did I do wrong?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
SELECT     TOP 100 PERCENT dbo.p21_view_invoice_hdr.company_no, dbo.p21_view_oe_hdr.customer_id, dbo.p21_view_oe_line.order_no, 
                      dbo.p21_view_oe_line.item_id, dbo.p21_inventory_usage_view.number_of_orders, dbo.p21_inventory_usage_view.number_of_hits, 
                      dbo.p21_inventory_usage_view.year_for_period, dbo.p21_inventory_usage_view.period, 
                      CASE Service_Level WHEN dbo.p21_inventory_usage_view.number_of_hits > 0 THEN ((dbo.p21_inventory_usage_view.number_of_hits / dbo.p21_inventory_usage_view.number_of_orders)
                       * 100) ELSE 0
FROM         dbo.p21_inventory_usage_view INNER JOIN
                      dbo.p21_view_oe_line ON dbo.p21_inventory_usage_view.item_id = dbo.p21_view_oe_line.item_id INNER JOIN
                      dbo.p21_view_oe_hdr ON dbo.p21_view_oe_line.order_no = dbo.p21_view_oe_hdr.order_no INNER JOIN
                      dbo.p21_view_invoice_hdr ON dbo.p21_view_oe_hdr.order_no = dbo.p21_view_invoice_hdr.order_no AND 
                      dbo.p21_inventory_usage_view.year_for_period = dbo.p21_view_invoice_hdr.year_for_period AND 
                      dbo.p21_inventory_usage_view.period = dbo.p21_view_invoice_hdr.period AND 
                      dbo.p21_inventory_usage_view.company_id = dbo.p21_view_invoice_hdr.company_no
GROUP BY dbo.p21_view_oe_hdr.customer_id, dbo.p21_view_oe_line.order_no, dbo.p21_view_oe_line.item_id, 
                      dbo.p21_inventory_usage_view.number_of_orders, dbo.p21_inventory_usage_view.number_of_hits, dbo.p21_inventory_usage_view.year_for_period, 
                      dbo.p21_inventory_usage_view.period, dbo.p21_view_invoice_hdr.company_no
HAVING      (dbo.p21_view_oe_hdr.customer_id = 4632) AND (dbo.p21_view_invoice_hdr.company_no = '01') AND 
                      (dbo.p21_inventory_usage_view.year_for_period = 2008)
ORDER BY dbo.p21_view_oe_line.order_no, dbo.p21_view_oe_line.item_id
[+][-]04.28.2008 at 08:00AM PDT, ID: 21454624

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: Microsoft, SQL Server, 2000, Query Analyzer
Sign Up Now!
Solution Provided By: aneeshattingal
Participating Experts: 3
Solution Grade: A
 
 
[+][-]04.28.2008 at 08:00AM PDT, ID: 21454628

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 08:02AM PDT, ID: 21454638

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 - Hierarchy / EE_QW_2_20070628