Avatar of kelsanit
kelsanit
 asked on

Crystal reports - SQL Command add field

have the following SQL Comman where the SmsnMaster.SalesRepName does not appear as a field name in Crystal. When I try and add to the select statement it tells me it could not be bound.



WITH Orders (TakenBy, InvoiceDate, PlacedBy,District,OrderNumber,OutsideSalesRep,SalesRepName)
AS
(
    SELECT "OrderHeaderMaster"."TakenBy",
           "OrderHeaderMaster"."InvoiceDate",
           "OrderHeaderMaster"."PlacedBy",
           "SmsnMaster"."District",
           "OrderHeaderMaster"."OrderNumber",
           "CustomerMaster"."OutsideSalesRep",
           "SmsnMaster"."SalesRepName"
    FROM   "ksdb_eff"."dbo"."OrderHeaderMaster" "OrderHeaderMaster"
           INNER JOIN (
                    "ksdb_eff"."dbo"."SmsnMaster" "SmsnMaster" INNER JOIN
                    "ksdb_eff"."dbo"."CustomerMaster" "CustomerMaster" ON
                    "SmsnMaster"."SalesRepNumber" = "CustomerMaster"."OutsideSalesRep"
                )
                ON  "OrderHeaderMaster"."CustomerNumber" = "CustomerMaster"."CustomerNumber"
    WHERE  NOT (
               "SmsnMaster"."District" = 'krystal'
               OR "SmsnMaster"."District" = 'no manager'
           )
           AND "OrderHeaderMaster"."InvoiceDate" >= {ts '2011-08-02 00:00:00'}
           AND "SmsnMaster"."SalesRepName" <> 'available'
)

SELECT tm.OutsideSalesRep,tm.Orders AS TMOrders,onln.Orders AS OnlineOrders, convert(decimal(10,4),isnull(onln.Orders,0))/convert(decimal(10,4),tm.Orders)  AS BIZcPr


FROM (
                  SELECT o.OutsideSalesRep,COUNT(*) as Orders
                  FROM Orders o
                  GROUP BY  o.OutsideSalesRep
                  ) tm
      LEFT JOIN (
                                          SELECT oo.OutsideSalesRep, COUNT(*) AS Orders
                                          FROM Orders oo
                                          WHERE TakenBy = 'WWW'
                                          GROUP BY oo.OutsideSalesRep

) onln ON tm.OutsideSalesRep = onln.OutsideSalesRep;

Crystal ReportsMySQL Server

Avatar of undefined
Last Comment
kelsanit

8/22/2022 - Mon
kelsanit

ASKER
I also need the District as a filed to pull into the report.
ASKER CERTIFIED SOLUTION
Mike McCracken

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
kelsanit

ASKER
when i use the select query above it give me the following message now.

Orders.SalesRepName is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23