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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:24:55+00:00 2026-05-26T03:24:55+00:00

I have the following SQL stored procedure that when I try to save it,

  • 0

I have the following SQL stored procedure that when I try to save it, it complains about “Invalid column name ‘Goal'” in the last select statement.

Can someone tell me why this is an invalid comlumn name? I am doing basically the same thing for NetSales and it doesn’t complain about that column.

if object_id('tempdb..#tmpHours') is not null
    DROP TABLE #tmpHours
if object_id('tempdb..#tmpPay') is not null
    DROP TABLE #tmpPay

SET @MondayOfCurrentWeek = (SELECT DATEADD(wk, DATEDIFF(wk,0,@WeekOf), 0) )

SELECT  p.PerceptionistID AS PerceptionistID, p.BaseCommission AS BaseCommission, p.BonusCommission AS BonusCommission, 
        h.WeekOf AS WeekOf, h.WorkHours AS WorkHours, h.PTOHours AS PTOHours, h.HolidayHours AS HolidayHours,
        ROUND(h.WorkHours, 0) AS HoursRounded, 
        (
            SELECT COUNT(c.PerceptionistID)
            FROM T_Call c 
            WHERE 
                c.PerceptionistID = p.PerceptionistID 
                AND c.OutcomeID = @OutcomeSale 
                AND EnteredOn BETWEEN @MondayOfCurrentWeek AND DATEADD(dd, 7, @MondayOfCurrentWeek)
        ) AS GrossSales,
        (
            SELECT COUNT (c.PerceptionistID)
            FROM T_CallCredit cc
                INNER JOIN T_Call c
                    ON cc.CallID = c.CallID
            WHERE 
                c.PerceptionistID = p.PerceptionistID 
                AND cc.CallCreditStatusID NOT IN (17, 18)  -- 17 - 'Error in Customer Account', 18 - 'Courtesy Credit'
                AND cc.EnteredOn BETWEEN @MondayOfCurrentWeek AND DATEADD(dd, 7, @MondayOfCurrentWeek)
        ) AS Credits

INTO #tmpHours
FROM T_Perceptionist p
    RIGHT JOIN T_PerceptionistHours h
        ON p.PerceptionistID = h.PerceptionistID
WHERE h.WeekOf = @MondayOfCurrentWeek


SELECT  PerceptionistID, CAST((HoursRounded*2) AS int) AS Goal, GrossSales, Credits, (GrossSales - Credits) AS NetSales, 
        HoursRounded, WorkHours, PTOHours, HolidayHours, BaseCommission, BonusCommission, 
        [dbo].fnCalculateCommission(BaseCommission, BonusCommission, (GrossSales - Credits), CAST((HoursRounded*2) AS int)) AS CommissionPay
INTO #tmpPay    
FROM #tmpHours 


--- Complains about column name 'Goal' in the following statement
SELECT  PerceptionistID, Goal, GrossSales, Credits, NetSales, HoursRounded, WorkHours, PTOHours, 
        HolidayHours, BaseCommission, BonusCommission, CommissionPay
FROM #tmpPay
  • 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-26T03:24:56+00:00Added an answer on May 26, 2026 at 3:24 am

    Try running it in a new connection or dropping the temp tables in a separate batch first.

    Possibly the #temp tables are still hanging about from a previous batch when you did not have the Goal column and the parser validates the column names against the existing table, encounters a binding error and refuses to run the batch.

    If the temp tables don’t exist at all compilation of the statement will be deferred.

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

Sidebar

Related Questions

We have the following simple Stored Procedure that runs as an overnight SQL server
I have the following stored procedure that I working on. I have noticed that
i have the following stored procedure that returns the sent emails of the latest
I have a stored procedure that retrieves sensitive information from an SQL Server 2008
I have the following requirements I have relational content stored in a SQL Server
I have the following SQL-statement: SELECT DISTINCT name FROM log WHERE NOT name =
I have a following SQL QUERY: SELECT articles.name, articles.price, users.zipcode FROM articles INNER JOIN
I have the following Sql Query that returns the type of results that I
I have the following stored procedure ALTER PROCEDURE [dbo].Test AS BEGIN CREATE TABLE ##table
I use the following stored procedure from my SQL Server 2008 database to return

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.