question archive Write a SELECT statement that returns the InvoiceNumber and balance due for every invoice with a non-zero balance and an InvoiceDueDate that’s less than one month from today

Write a SELECT statement that returns the InvoiceNumber and balance due for every invoice with a non-zero balance and an InvoiceDueDate that’s less than one month from today

Subject:StatisticsPrice:3.87 Bought7

Write a SELECT statement that returns the InvoiceNumber and balance due for every invoice with a non-zero balance and an InvoiceDueDate that’s less than one month from today.

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

Answer:

I have modified the SQL query that you shown in the question 

As you don't give the actual table data so i have used temporary table with some dummy data in it for Invoices.

In the below query please replace the table name from #Invoices to Invoice while you execute in your database

I have added temp table just for showing the result please remoive all the bolder text in below query and rename the table name from #Invoices to Invoice

SQL CODE

IF OBJECT_ID('tempdb..#Invoices') IS NOT NULL

DROP TABLE #Invoices

SELECT '989319-457' As InvoiceNumber,0 As BalanceDue,'03-21-2018' As InvoiceDueDate INTO #Invoices

UNION

SELECT '989319-458' As InvoiceNumber,23 As BalanceDue,'03-25-2018' As InvoiceDueDate

UNION

SELECT '989319-459' As InvoiceNumber,50 As BalanceDue,'03-19-2018' As InvoiceDueDate

UNION

SELECT '989319-460' As InvoiceNumber,60 As BalanceDue,'03-19-2018' As InvoiceDueDate

SELECT * FROM #Invoices

SELECT

InvoiceNumber,

BalanceDue

From #Invoices

WHERE InvoiceDueDate < DATEADD(m, -1, GETDATE())

AND BalanceDue > 0

Output Screen

PFA