Avatar of 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)
    SELECT "OrderHeaderMaster"."TakenBy",
    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

                  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

8/22/2022 - Mon

I also need the District as a filed to pull into the report.
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
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
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.

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.