Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6805711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:37:12+00:00 2026-05-26T19:37:12+00:00

I’m getting the error Must declare @sales_total when I run this query: –temp Department

  • 0

I’m getting the error “Must declare @sales_total” when I run this query:

--temp Department table needed to handle plywood mills where sawlines are not yet 
DECLARE @Department TABLE
(Department_number uniqueidentifier
,Process_number uniqueidentifier
,Department_Name nvarchar(100))

INSERT @Department 
(Department_number 
,Process_number 
,Department_Name)
((SELECT 'D3BC304C-E3EF-4119-AF9B-02253114B4F2', '87B1D819-06A6-4551-A8AE- 349232F652EC','Elgin.Sawline')  -- Elgin Sawline from Layup
UNION (SELECT '6A5A052C-65B3-4F09-8A85-7E1CD5EF5003', '5CA0310F-D9AA-4E0E-AFAB-DFB77A2A19AD','KF.Sawline')  -- KF Sawline from Layup
UNION (SELECT '81F4E6F2-AC8B-4002-8A40-0D8A632CB041','C86711E2-F86B-4F20-AF44-378791D0369F' ,'MedfordPly.Sawline')  --Medford Sawline from spray line
UNION (SELECT '81F4E6F2-AC8B-4002-8A40-0D8A632CB041','BA420B4D-B413-4F53-A34E-7E1A43B42824' ,'MedfordPly.Sawline')  --Medford Sawline from curtain coater
UNION (SELECT '335465EB-54A1-48E2-A69F-671A38BF7B84','36FD8A9A-0CCE-4B86-972F-F0DD3DF4813D' ,'Oakdale.Sawline') --Oakdale actual sawline
UNION (SELECT '089B086A-E431-4691-B2F0-5F84EBE31F80','86EDB559-4C53-4261-BB32-372677CD4231'              ,'Florien.Sawline') --Florien actual sawline
)
-- temp production table
Declare @Production TABLE
(Plant_Number uniqueidentifier
,Plant_name       nvarchar (50)
,Department_number uniqueidentifier
,Production_Date datetime
,Production_Volume decimal(18,6))

Insert into @Production 
(Plant_Number
,Plant_name
,Department_number
,Production_Date
,Production_Volume)

(
SELECT p.[Plant_Number]
           ,p.plant_name    
  ,d.department_number
  ,pf.date
  ,(ppf.Good_Output/1000)

FROM @Department D
Inner join [TrueOpportunity].[dbo].[Department] dpt
on d.department_number = dpt.department_number

inner join [TrueOpportunity].[dbo].[Plant] p
on p.plant_number = dpt.plant_number

inner join [TrueOpportunity].[dbo].[Process] prc
on d.process_number = prc.process_number

inner join [TrueOpportunity].[dbo].[Production_Fact] pf
on prc.process_number = pf.process_number
--and Month (pf.date) = Month (@monthtodate)

inner join [TrueOpportunity].[dbo].[Production_Process_Fact] ppf
on ppf.production_number = pf.production_number  

--Group by p.Plant_Number, d.Department_number, pf.date, p.plant_name, ppf.Good_Output
)  

Declare @ProdTotal TABLE
(Plant_Number uniqueidentifier
,Plant_name       nvarchar (50)
,Production_Volume decimal(18,6)
,Prod_date datetime)

Insert into @ProdTotal 
(Plant_Number 
,Plant_name 
,Production_Volume
,Prod_date
)


(SELECT   
p.plant_number
,p.plant_name
,sum(p.production_volume) 
,p.production_date
from @Production p
--where plant_name = 'Medford Plywood'
where Production_date between @BeginningDate and @EndingDate

group by p.plant_number
,p.plant_name
,p.production_date)

Declare @Sales TABLE
(Plant_Number uniqueidentifier
,Plant_name       nvarchar (50)
,Actual_Volume decimal(18,6)
,Budget_Volume decimal(18,6)
,Actual_Sales_Dollars decimal(18,6)
,Average_Price decimal(18,6)
,sales_date datetime)

Insert into @Sales 
(Plant_Number 
,Plant_name 
,Actual_Volume
,Budget_Volume
,Actual_Sales_Dollars
,Average_Price
,Sales_Date)

(SELECT   P.[Plant_Number]
          ,pls.plant_code
          ,(pls.[Actual_Volume])  
          ,(pls.[Budget_Volume])
          ,(pls.[Actual_Sales_Dollars])
          ,CASE                    
            WHEN   coalesce (pls.[Actual_Volume],0) = 0 and
                   coalesce (pls.[Actual_Sales_Dollars],0) = 0
                   THEN 0
            ELSE ((pls.[Actual_Sales_Dollars]/pls.[Actual_Volume]))     
            END   AS 'Average Price'
           ,pls.production_date 

FROM woodproduction.dbo.plywood_layup_sales pls
inner join @Production p
on p.plant_number = pls.plant_number
           and p.production_date = pls.production_date

left join woodproduction.dbo.process_inventory pinv
on pinv.plant_code = pls.plant_code
and pinv.inventory_date = pls.production_date

left join trueopportunity.dbo.process prc
on pinv.department_number = prc.department_number




WHERE 
    pls.production_date between @BeginningDate and @EndingDate
    and pls.actual_volume <> 0

GROUP BY
P.[Plant_Number]
,pls.plant_code
,pls.production_date
,pls.[Actual_Volume]  
,pls.[Budget_Volume]
,pls.[Actual_Sales_Dollars]

)
--select * from @Sales

Declare @Sales_TOTAL TABLE
(Plant_Number uniqueidentifier
,Plant_name       nvarchar (50)
,Actual_Volume decimal(18,6)
,Budget_Volume decimal(18,6)
,Actual_Sales_Dollars decimal(18,6)
,Average_Price decimal(18,6)
,sales_date datetime)

Insert into @Sales_TOTAL
(Plant_Number 
,Plant_name 
,Actual_Volume
,Budget_Volume
,Actual_Sales_Dollars
,Average_Price
,sales_date)

(Select
s.Plant_Number 
,s.Plant_name 
,sum(s.Actual_Volume)
,sum(s.Budget_Volume)
,sum(s.Actual_Sales_Dollars)
,CASE                    
WHEN coalesce (sum(s.Actual_Volume),0) = 0 
THEN 0
ELSE (sum(s.Actual_Sales_Dollars)/sum(s.Actual_Volume))     
END                      
AS 'Average Price'
,s.sales_date

 from @Sales s
where s.sales_date between @BeginningDate and @EndingDate

group by s.plant_number, s.plant_name, s.sales_date

)

--Select * from @Sales_Total


Declare @Sales_Prod TABLE
(Plant_Number uniqueidentifier
,Plant_name       nvarchar (50)
,Actual_Volume decimal(18,6)
,Budget_Volume decimal(18,6)
,Actual_Sales_Dollars decimal(18,6)
,Average_Price decimal(18,6)
,Production_Volume decimal(18,6)
,sales_date datetime)

Insert into @Sales_Prod
(Plant_Number 
,Plant_name 
,Actual_Volume
,Budget_Volume
,Actual_Sales_Dollars
,Average_Price
,Production_Volume
,sales_date)

(Select
st.Plant_Number 
,st.Plant_name 
,st.Actual_Volume
,st.Budget_Volume
,st.Actual_Sales_Dollars
,st.Average_Price
,pt.Production_Volume
,st.sales_date

from @Sales_Total st
,@ProdTotal pt
where st.sales_date = pt.prod_date
and st.plant_number = pt.plant_number
and st.sales_date between @BeginningDate and @EndingDate
)

--Select * from @Sales_Prod

When I run this query in Management Studio and substitute my date parameters for an actual date, i get the data I am expecting. So I copied/pasted it into SSRS 2008 and then made sure I removed all of my temp dates and replaced them with my ‘between @beg..@end’ parameter. But for some reason @sales_total is showing up as a ‘Define Query Parameters’and I’ve been looking at it and can’t see where, other than DECLARE @Sales_Total TABLE that @sales_total appears by itself as a separate parameter.

Can someone please take a look and see what I’m missing. Maybe I’ve been staring at it too long? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:37:12+00:00Added an answer on May 26, 2026 at 7:37 pm

    It’s case sensitive… You declared Sales_TOTAL, and you tried select from Sales_Total.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I am using Paperclip to handle profile photo uploads in my app. They upload
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.