Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic SQL: Add column to select statement (ie value from another table)

Status
Not open for further replies.

michellepace

Technical User
Sep 12, 2020
7
ZA
Hi there,

I need to add a 4th column to my current select statement on LedgerTransactions. This fourth column is the company name which is obtained from (select CoName FROM LedgerParameters). There are no shared columns between these two tables for me to do a join. For a better explanation, please see my screenshot attached.

Could somebody please help me write a single SQL statement to result in my four-column table?

screenshot_ymaxd8.png


Thank you in advance,
Michelle
 
Not to worry thank you, I found the answer!

SELECT AutoNumber,DDAte,Amount*(-1) as Amount, (select CoName from LedgerParameters) as Company
FROM LedgerTransactions LT
WHERE DDATE >= DATEFROMPARTS(2019,01,01)
AND LT.AccNumber IN
(select distinct AccNumber FROM LedgerMaster)
ORDER BY ddate DESC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top