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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:20:31+00:00 2026-05-31T15:20:31+00:00

I hope this is formatted right. I’m having a problem with this procedure. I’ve

  • 0

I hope this is formatted right. I’m having a problem with this procedure. I’ve stripped out the declaration and what you see is the main body. All I am trying to do is create a table variable (in SQL SERVER 2000) and pull some metrics from the data contained within.

DECLARE @InvoiceData TABLE
(
UserID      INT
, FullName  VARCHAR
, StatusId  INT
, Status    VARCHAR
, DateCreated DATETIME
)

--INSERT INTO @InvoiceData(UserID, FullName, StatusId, Status, DateCreated)
SELECT
tblInvoiceInstructions.AccountantUserId
, Users.Name + ', ' + Users.First_Name AS FullName
, tblInvoice.CurrentWorkflowStatusId AS StatusID
, dbo.ufnGetGenericCodeLongDescText(tblInvoice.CurrentWorkflowStatusId,GETDATE()) AS Status
, CONVERT(VARCHAR, tblInvoice.DateCreated, 101) AS DateCreated
FROM tblInvoiceInstructions
JOIN tblInvoice ON tblInvoice.Project_ID = tblInvoiceInstructions.ProjectID
LEFT JOIN dbo.Users ON tblInvoiceInstructions.AccountantUserId = Users.UserId
WHERE tblInvoice.DateCreated BETWEEN @StartDate AND @EndDate


SELECT FullName, InvoicesAssigned, InvoicesApproved, InvoicesRejected, InvoicesAssigned-InvoicesApproved-InvoicesRejected AS InvoicesRemaining
FROM 
(
SELECT DISTINCT FullName
,ISNULL((SELECT COUNT(t2.StatusID) FROM @InvoiceData t2 WHERE t2.AccountantUserId = T1.AccountantUserId GROUP BY FullName),0) AS InvoicesAssigned
,ISNULL((SELECT COUNT(t2.StatusID) FROM @InvoiceData t2 WHERE t2.StatusID = 394 AND t2.AccountantUserId = T1.AccountantUserId GROUP BY FullName),0) AS InvoicesApproved
,ISNULL((SELECT COUNT(t2.StatusID) FROM @InvoiceData t2 WHERE t2.StatusID = 388 AND t2.AccountantUserId = T1.AccountantUserId GROUP BY FullName),0) AS InvoicesRejected
FROM @InvoiceData T1
) AS InnerTable

When I execute the stored procedure, it gives me the following error 6 times:

Msg 207, Level 16, State 3, Procedure uspReportInvoicesProcessedAndWaiting, Line 31
Invalid column name ‘AccountantUserId’.

Line 31 is the outer select where I am pulling values for FullName, InvoicesAssigned, InvoicesApproved. and so on. Am I aliasing the tables incorrectly?

  • 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-31T15:20:32+00:00Added an answer on May 31, 2026 at 3:20 pm

    Check this line in the second query.

    ISNULL((SELECT COUNT(t2.StatusID) FROM @InvoiceData t2 
    WHERE t2.AccountantUserId = T1.AccountantUserId GROUP BY FullName),0) 
    AS InvoicesAssigned
    

    NOTE: @InvoiceData Alias t2 has no AccountantUserId column defined.
    t2.AccountantUserId does not exist.

    Check the @InvoiceData table definition

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

Sidebar

Related Questions

Hope this is the right place to be asking this, so my apologies if
I hope this is a simple enough question for any SQL people out there...
I hope this is the appropriate title for this question. Right now I have
I hope this is the right forum for this, and excuse the naive question.
I'm having a little problem with numbers in PHP, this is basically what I'm
(I hope this is a right description for what I want to achieve -
(Hope this doesn't get duplicated; second attempt at submitting this question) I'm working on
Hope this is not a dupe. I would like to be able to do
Hope this isn't a waste of your time. I'm working on a project, and
Hope this makes sense... Is there a simple way to return a set of

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.