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 8601997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:58:26+00:00 2026-06-12T01:58:26+00:00

CREATE PROCEDURE [dbo].[rpt_Report] @Product varchar(20) = NULL, @From DateTime = null, @To DateTime =

  • 0
CREATE PROCEDURE [dbo].[rpt_Report]
   @Product varchar(20) = NULL,
   @From DateTime = null,
   @To DateTime = null
AS
BEGIN
    SELECT 
       CO.PO, CO.DLVRY,   
       CASE
          WHEN co.CUST_ID = '120' THEN '120' 
          WHEN HDR.PO_NO LIKE 'CL%' THEN 'CL'
          WHEN RED.REU = 'SK' THEN 'STOCK' 
          WHEN RED.REU = 'SM' THEN 'ORTS' 
          WHEN co.ITEM = 'PW%' THEN 'CHAIN' 
          WHEN co.ITEM LIKE 'D%' THEN 'VAN' ELSE 'MISC' 
       END AS PRODUCT 
     FROM   
        co AS co    
     INNER JOIN 
        HDR AS HDR ON co.NUMBER = HDR.NUMBER 
     INNER JOIN 
        RED AS RED ON co.ITEM = RED.ITEM 
     WHERE   
        (co.DLVRY BETWEEN @From AND @To) AND (@Product = PRODUCT)
     ORDER BY
        co.DLVRY DESC
END

When I execute it I am getting an error saying

Msg 207, Level 16, State 1, Procedure rpt_Report, Line 34
Invalid column name ‘PRODUCT’.

I should use the case field value as parameter in where CLAUSE.

  • 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-06-12T01:58:28+00:00Added an answer on June 12, 2026 at 1:58 am

    It appears that you are attempting to use the PRODUCT alias in the WHERE clause, which you cannot do. So you can wrap the query in a sub-query to use the alias:

    CREATE PROCEDURE [dbo].[rpt_Report]
       @Product varchar(20) = NULL,
       @From DateTime = null,
       @To DateTime = null
    AS
    BEGIN
        SELECT x.PO, x.DLVRY, x.PRODUCT
        FROM
        (
            SELECT CO.PO, CO.DLVRY,   
               CASE
                  WHEN co.CUST_ID = '120' THEN '120' 
                  WHEN HDR.PO_NO LIKE 'CL%' THEN 'CL'
                  WHEN RED.REU = 'SK' THEN 'STOCK' 
                  WHEN RED.REU = 'SM' THEN 'ORTS' 
                  WHEN co.ITEM = 'PW%' THEN 'CHAIN' 
                  WHEN co.ITEM LIKE 'D%' THEN 'VAN' ELSE 'MISC' 
               END AS PRODUCT 
             FROM  co AS co    
             INNER JOIN HDR AS HDR 
                ON co.NUMBER = HDR.NUMBER 
             INNER JOIN RED AS RED 
                ON co.ITEM = RED.ITEM 
        ) x        
        WHERE (x.DLVRY BETWEEN @From AND @To) 
            AND (@Product = PRODUCT)
        ORDER BY x.DLVRY DESC
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

create procedure [dbo].[MySproc] @Value bit = null as select columna from tablea where columnb
I have developed the following code: CREATE PROCEDURE [dbo].[Test01] AS BEGIN SELECT * FROM
CREATE PROCEDURE [dbo].[PL_GEN_PROVN_NO1] @GAD_COMP_CODE VARCHAR(2) =NULL, @@voucher_no numeric =null output AS BEGIN DECLARE @NUM
CREATE PROCEDURE [dbo].[FlowClientGetNum] (@ID_ListGroupParIzm Integer, @ID_ListParIzm Integer) AS SELECT Number of my @ID_ListParIzm FROM
I wrote a stored procedure with optional parameters. CREATE PROCEDURE dbo.GetActiveEmployee @startTime DATETIME=NULL, @endTime
create procedure [dbo].[teststoredproc] (@startDate datetime, @endDate datetime) as begin set nocount on; merge TargetTable
CREATE PROCEDURE [dbo].[proc1] ( @tbl1 varchar(30), @var2 varchar(7000) ) AS BEGIN DECLARE @sql VARCHAR(8000)
I have written a simple procedure: CREATE PROCEDURE [dbo].[sp_GetPublishedDocs2] @FromDate as Datetime AS BEGIN
I want to write a stored procedure like this Create Proc dbo.GetApplicantsByIDs as Select
Given this : delimiter // create procedure setup() begin declare d datetime; set d

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.