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

  • Home
  • SEARCH
  • 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 7674117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:40:03+00:00 2026-05-31T16:40:03+00:00

When I run my final query I am getting the above error. I’ve set

  • 0

When I run my final query I am getting the above error. I’ve set my table format properly and if I run my @ProdTotal query separately I get the correct data and the same for if I run the final @Sales_Prod query WITHOUT bringing in pt.Production_Volume.

The error specifically points to Line 99 which is where INSERT INTO @Production begins.
Why am I getting the error if my pt.Production_Volume is set to DECIMAL(18,6)? Is it because I’m use a CASE statement?

Here is my whole query:

DECLARE @BeginningDate  datetime
DECLARE @EndingDate     datetime

SET @BeginningDate  =   '03-01-2012'
SET @EndingDate     =   '03-20-2012'

DECLARE @Proc       TABLE
(
Process_Number      UNIQUEIDENTIFIER
,Process_Name       NVARCHAR(50)
)

Insert into @Proc
(
Process_Number      
,Process_Name
)
(
(Select '60203D01-FEAA-4F4B-BFC8-F6C6BD7D9977','Alex.I-Line')
Union (Select '4F980EDF-9EE4-41A1-9DBD-BE12FE227199', 'Alex.Versa Lam')
Union (Select 'B7AB6C1E-2897-4C3F-A6C4-B53E996288ED', 'WCEWP.I-Line')
Union (Select '44A7E9C7-FEE7-4DEA-8826-D10CCCF5FA0F', 'WCEWP.Versa Lam')
Union (Select '079632C7-ADD7-47AF-89AB-B28CDDBA2AD5','StJ.I-Line')
)

--Select * from @Prod
DECLARE @Plant      TABLE
(
Department_Number   UNIQUEIDENTIFIER
,Process_Number     UNIQUEIDENTIFIER
,Process_Name       NVARCHAR(50)
,Plant_Number       UNIQUEIDENTIFIER
,Plant_Name         NVARCHAR(50)
)

INSERT INTO @Plant
(
Department_Number
,Process_Number
,Process_Name
,Plant_Number
,Plant_Name
)
(
SELECT 

d.department_number
,pr.process_number
,pr.Process_name
, p.plant_number
, p.plant_name

FROM trueopportunity.dbo.Process pr
inner join trueopportunity.dbo.department d
on pr.department_number = d.department_number

inner join @Proc pro
on pr.process_number = pro.process_number

inner join trueopportunity.dbo.plant p
on d.plant_number = p.plant_number
)

--SELECT * FROM @Plant

Declare @Product_Name   Table
(
Product_Group_Number    uniqueidentifier
,Product_Name           nvarchar(50)
)

INSERT INTO @Product_Name
(
Product_Group_Number
,Product_Name
)
(
(SELECT 'FE1EC4A8-FEC4-4F45-B74F-72528967DB4B', 'I-Joists ')
UNION(SELECT '0A32AA2B-2630-4090-ADA1-33FAD888FA27', 'Rimboard')
UNION(SELECT '38B67F82-9259-417D-83AF-493CBF953FD1','Versa Lam')
)

--SELECT * FROM @Product_Name

DECLARE @Production     TABLE

(
Production_Process_Number       uniqueidentifier
,Production_Number              uniqueidentifier
,Process_Number                 uniqueidentifier
,Process_Name                   nvarchar(50)
,Plant_Name                     nvarchar(50)
,Plant_Number                   uniqueidentifier
,Production_Volume              decimal(18,6)
,Production_Date                datetime
,Product_Group_Name             nvarchar(50)
)

INSERT INTO @Production
(
Production_Process_Number
,Production_Number  
,Process_Number 
,Process_Name
,Plant_Number
,Plant_Name
,Production_Volume  
,Production_Date
,Product_Group_Name
)
(SELECT

ppf.Production_Process_Number
,ppf.Production_Number
,pl.process_number
,pl.Process_Name 
,pl.plant_name
,Plant_Number
,CASE   
WHEN  (pg.Product_Group_Name) = 'I-Joist' THEN (sum(ppf.Good_Output)) 
ELSE  (sum(ppf.Good_Output_Product_Units))
END as 'Prod Vol'
, pf.date 
, pg.product_group_name

FROM
trueopportunity.dbo.Production_Fact pf
Inner Join trueopportunity.dbo.Production_Process_Fact ppf
on pf.production_number = ppf.production_number

inner join @Plant pl
on pf.process_number = pl.process_number

inner join trueopportunity.dbo.Product prd
on pf.product_number = prd.product_number

inner join trueopportunity.dbo.Product_Group pg
on pg.product_group_number = prd.product_group_number

inner join @Product_Name pn
on pn.product_group_number = prd.product_group_number 

and
pf.date between @BeginningDate and @EndingDate

GROUP BY
Plant_Number
,pl.plant_name
,pg.product_group_name
,prd.product_name 
,pl.Process_Name
,pl.process_number
,ppf.Production_Process_Number
,ppf.Production_Number
,pf.date
)

ORDER BY
pf.date

--SELECT * FROM @Production

DECLARE @ProdTotal      TABLE
(
Plant_Number            UNIQUEIDENTIFIER
,Plant_Name             NVARCHAR(50)
,Production_Volume      DECIMAL(18,6)
,Product_Group_Name     NVARCHAR(50)
) 
Insert into @ProdTotal 
(
Plant_Number    
,Plant_name 
,Production_Volume
,Product_Group_Name
)
(SELECT 
p.plant_number
,p.plant_name
,sum(p.production_volume) 
,p.product_group_name

FROM @Production p

 WHERE Production_date between @BeginningDate and @EndingDate

GROUP BY
p.plant_number
,p.plant_name
,p.product_group_name

)
order by  p.plant_name

--select * from @ProdTotal  

DECLARE @EWPSales       TABLE
(
Plant_Number            UNIQUEIDENTIFIER
,Plant_Code             NVARCHAR(100)
,Process_Number         UNIQUEIDENTIFIER
,Product_Group_Code     NVARCHAR(100)
,Actual_Volume          DECIMAL(18,6)
,Actual_Sales_Dollars   DECIMAL(18,6)
,Avg_Price              DECIMAL(18,6)
,Production_Date        DATETIME
)

INSERT INTO @EWPSales
(
Plant_Number
,Plant_Code 
,Process_Number 
,Product_Group_Code
,Actual_Volume
,Actual_Sales_Dollars
,Avg_Price
,Production_Date
)

(
SELECT
esl.Plant_Number
,esl.Plant_Code 
,esl.Process_Number 
,esl.Product_Group_Code
,(esl.Actual_Volume )
,esl.Actual_Sales_Dollars
,CASE                    
  WHEN   coalesce (esl.Actual_Volume,0) = 0 and
      coalesce (esl.Actual_Sales_Dollars,0) = 0
      THEN 0
      ELSE (sum(esl.Actual_Sales_Dollars)/sum(esl.Actual_Volume))     
  END AS 'AVG PRICE'
,esl.Production_Date

FROM
WOODPRODUCTION.DBO.EWP_Sales esl


Where esl.Production_Date between @BeginningDate and @EndingDate


GROUP BY
esl.Plant_Number
,esl.Plant_Code 
,esl.Process_Number 
,esl.Product_Group_Code
,esl.Actual_Volume
,esl.Actual_Sales_Dollars
,esl.Production_Date
)
ORDER BY
esl.Production_Date 

--Select * from @EWPSales

Declare @Sales_Total        TABLE
(Plant_Number           UNIQUEIDENTIFIER
,Plant_name             NVARCHAR (50)
,Product_Group_Code     NVARCHAR(100)
,Actual_Volume          DECIMAL(18,6)
,Actual_Sales_Dollars   DECIMAL(18,6)
,Avg_Price              DECIMAL(18,6)
,sales_date             DATETIME
)

Insert into @Sales_Total
(Plant_Number 
,Plant_name 
,Product_Group_Code     
,Actual_Volume
,Actual_Sales_Dollars
,Avg_Price
,Sales_Date)

(
SELECT
s.Plant_Number 
,s.Plant_Code 
,s.Product_Group_Code       
,(s.Actual_Volume)
,(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     
,s.production_Date


FROM @EWPSales s
WHERE s.production_date between @BeginningDate and @EndingDate

GROUP BY
s.plant_number
,s.plant_code
,s.Product_Group_Code   
,(s.Actual_Volume)  
,s.production_date
,s.Actual_Sales_Dollars
,s.avg_price
)

ORDER BY s.production_date
--Select * from @Sales_Total

Declare @Sales_Prod         TABLE
(
Plant_Number                UNIQUEIDENTIFIER
,Plant_Name                 NVARCHAR (50)
,Product_Group_Code         NVARCHAR(100)
,Actual_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 
,Product_Group_Code
,Actual_Volume
,Actual_Sales_Dollars
,Average_Price
,Production_Volume
,Sales_Date
)

(
SELECT 
st.Plant_Number 
,st.Plant_name 
,st.Product_Group_Code  
,st.Actual_Volume
,st.Actual_Sales_Dollars 
,st.Avg_Price  
,pt.Production_Volume
,st.Sales_Date


FROM @Sales_Total st
inner join @EWPSales s
on st.plant_number = s.plant_number

inner join @ProdTotal pt
on pt.plant_number = st.plant_number

and st.sales_date between @BeginningDate and @EndingDate

GROUP BY
st.Plant_Number 
,st.Plant_name 
,st.Product_Group_Code  
,st.Actual_Volume
,st.Actual_Sales_Dollars 
,st.Avg_Price  
,pt.Production_Volume
,st.Sales_Date

)
Order by st.Plant_name, st.sales_date
Select * from @Sales_Prod

tl;dr: I’m getting the above error starting at my INSERT INTO @Production line and I’m not sure why.

Thanks in advance everyone!

  • 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-31T16:40:04+00:00Added an answer on May 31, 2026 at 4:40 pm

    Plant_Number is a uniqueidentifier as per the declaration. But you are trying to insert pl.plant_name as the plant_Number. The columns in the SELECT statements have the wrong order

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

Sidebar

Related Questions

I have a query which I run on a table TXN_DEC(id, resourceid, usersid, date,
I'm trying to set up Haystack with Whoosh but am getting this value error
My final goal is to write the program which can run on the Unix
I'm trying to run a query from ADO.NET using SQL Server 2008R2. I'm using
I'm trying to run a webmethod via a jQuery which will query an SQL
I have a SQL query I'm running in an ASP.NET page. The final parsed
I am running a query in C++ but I can not get the date
Is there a good reliable way to determine where a Hibernate query is getting
This SQL query was generated by Microsoft Access 2003, and works fine when run,
I have a MySQL query that I'm trying to run in SQLite. I found

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.