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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:15:06+00:00 2026-06-11T01:15:06+00:00

I have this long sql query here.. SELECT c.clientid, c.clientname, c.billingdate, case when (select

  • 0

I have this long sql query here..

SELECT c.clientid, c.clientname, c.billingdate, 
case when (select ifnull(sum(total), 0) from invoice i
where i.client = c.clientid and i.isdeleted = 0) - (select ifnull(sum(p.amount), 0) from payment p inner join invoice i on p.invoice = i.invoiceid
where i.client = c.clientid and i.isdeleted = 0) < 0 and i.date < '2012-01-01' then (select ii.total from invoice ii where ii.client = c.clientid order by ii.invoiceid desc limit 1)  else (select ifnull(sum(total), 0) from invoice i
where i.client = c.clientid and i.isdeleted = 0) - (select ifnull(sum(p.amount), 0) from payment p inner join invoice i on p.invoice = i.invoiceid
where i.client = c.clientid and i.isdeleted = 0) end as remaining,
case c.isactive+0
        when '1' then 'Stop'
        else 'Start' 
        end as Active
FROM client c 
ORDER BY clientname

I get an error with this query with the line i.date < '2012-01-01' saying that i.date is an unknown column in field list…how do I fix this?

Thanks,
J

  • 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-11T01:15:07+00:00Added an answer on June 11, 2026 at 1:15 am

    You’re using alias i out of the scope, which is defined here, in the subquery

    (select ifnull(sum(total), 0) from invoice i
    where i.client = c.clientid and i.isdeleted = 0)
    

    with the ()

    you should change include this:

    and i.date < '2012-01-01'
    

    in both selects

    SELECT c.clientid, c.clientname, c.billingdate, 
    case when (select ifnull(sum(total), 0) from invoice i
    where i.client = c.clientid and i.isdeleted = 0 and i.date < '2012-01-01' ) - (select ifnull(sum(p.amount), 0) from payment p inner join invoice i on p.invoice = i.invoiceid
    where i.client = c.clientid and i.isdeleted = 0 and i.date < '2012-01-01' ) < 0 then (select ii.total from invoice ii where ii.client = c.clientid order by ii.invoiceid desc limit 1)  else (select ifnull(sum(total), 0) from invoice i
    where i.client = c.clientid and i.isdeleted = 0) - (select ifnull(sum(p.amount), 0) from payment p inner join invoice i on p.invoice = i.invoiceid
    where i.client = c.clientid and i.isdeleted = 0) end as remaining,
    case c.isactive+0
            when '1' then 'Stop'
            else 'Start' 
            end as Active
    FROM client c 
    ORDER BY clientname
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query in T-SQL 2008: SELECT a.Amount / ( SELECT SUM(b.Amount) FROM
I have this query in SQL Server 2005: SELECT J.JobID, dbo.tblCustomers.Name AS CustomerName, J.CustomerJobNumber,
I have this case <WrapPanel> <CheckBox>Really long name</CheckBox> <CheckBox>Short</CheckBox> <CheckBox>Longer again</CheckBox> <CheckBox>Foo</CheckBox> <Slider MinWidth=200
I have a pretty long SQL query that I use to, for all of
So here is my very long SQL query. Basically, I've got 2 school levels,
I have this SQL Query which should find the rank of a certain cook.
I have this long list of checkboxes with specific labels that look something like
I have this long list of checkboxes with specific labels that look something like
In my implementation I have this: /// <inheritdoc cref=IInterface{T} this[,]/> public T this[long row,
How change int value in block, I have this : __block long long size

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.