I am new to Macola and have worked with SQL before. I have a task to provide my boss the number of orders input into Macola yesterday. I have it running in our Report Portal and providing the data daily. The issue is I need to add to this report the user that input the order into Macola and I have come to realize that requires another table. My challenge is the join and the join for both parts of the query. I am hoping I can get a little help here. Those of you who review my query and say.. wow.. thats not right.. you are most likely correct.. but it does work... so.. any ideas how to add the user name from the oehdraud_sql table in both instances of the query.
Thanks for the help..
Select sum(OrdCount), DATENAME(WEEKDAY,MacolaDate) AS DAYWEEK, Cast(MacolaDate as Date) Mdate From (
SELECT oh.entered_dt as MacolaDate, count(distinct oh.ord_no) as ordCount
FROM OEORDHDR_SQL oh with (nolock)
INNER JOIN OEORDLIN_SQL ol with (nolock) ON oh.ord_type = ol.ord_type AND oh.ord_no = ol.ord_no
WHERE oh.entered_dt >= @DtBegin and oh.entered_dt <= @DtEnd
and oh.ord_type = 'O'
AND ol.loc = 'MOD'
group by oh.entered_dt
UNION
--Posted invoices
SELECT oh.entered_dt as MacolaDate, count(distinct oh.ord_no) as ordCount
FROM OEHDRHST_SQL oh with (nolock)
INNER JOIN OELINHST_SQL ol with (nolock) ON oh.ord_type = ol.ord_type
WHERE oh.entered_dt >= @DtBegin and oh.entered_dt <= @DtEnd
and oh.ord_type = 'O'
AND ol.loc = 'MOD'
group by oh.entered_dt) as DT
Group by MacolaDate
order by MacolaDate
Thanks for the help..
Select sum(OrdCount), DATENAME(WEEKDAY,MacolaDate) AS DAYWEEK, Cast(MacolaDate as Date) Mdate From (
SELECT oh.entered_dt as MacolaDate, count(distinct oh.ord_no) as ordCount
FROM OEORDHDR_SQL oh with (nolock)
INNER JOIN OEORDLIN_SQL ol with (nolock) ON oh.ord_type = ol.ord_type AND oh.ord_no = ol.ord_no
WHERE oh.entered_dt >= @DtBegin and oh.entered_dt <= @DtEnd
and oh.ord_type = 'O'
AND ol.loc = 'MOD'
group by oh.entered_dt
UNION
--Posted invoices
SELECT oh.entered_dt as MacolaDate, count(distinct oh.ord_no) as ordCount
FROM OEHDRHST_SQL oh with (nolock)
INNER JOIN OELINHST_SQL ol with (nolock) ON oh.ord_type = ol.ord_type
WHERE oh.entered_dt >= @DtBegin and oh.entered_dt <= @DtEnd
and oh.ord_type = 'O'
AND ol.loc = 'MOD'
group by oh.entered_dt) as DT
Group by MacolaDate
order by MacolaDate