Last post Feb 27, 2019 05:58 PM by mgebhard
Participant
858 Points
1472 Posts
Feb 27, 2019 05:36 PM|slimbunny|LINK
Please see my codes I need to get the record count, but have not formulated the code correctly, please help with your expertise to get a record count.
Goal: Return Record Count
SELECT Acolumn1, Bcolumn2, Ccolumn3
FROM [Test1]...TableA
WHERE Acolumn1 NOT IN (SELECT Acolumn1 FROM MyTable2 )
Instead of getting rows back how do I get a record count from the above query?
Thank you
All-Star
53091 Points
23659 Posts
Feb 27, 2019 05:58 PM|mgebhard|LINK
See the SQL docs.
https://docs.microsoft.com/en-us/sql/t-sql/functions/count-transact-sql?view=sql-server-2017
SELECT COUNT(Acolumn1) FROM [Test1]...TableA WHERE Acolumn1 NOT IN (SELECT Acolumn1 FROM MyTable2 )
Also, NOT IN can cause issues if there are NULL values in MyTable2.Acolumn1. A Join is better as it handles NULL as you likely expect.
https://docs.microsoft.com/en-us/sql/relational-databases/performance/joins?view=sql-server-2017
Participant
858 Points
1472 Posts
Help getting record count...
Feb 27, 2019 05:36 PM|slimbunny|LINK
Please see my codes I need to get the record count, but have not formulated the code correctly, please help with your expertise to get a record count.
Goal: Return Record Count
SELECT Acolumn1, Bcolumn2, Ccolumn3
FROM [Test1]...TableA
WHERE Acolumn1 NOT IN (SELECT Acolumn1 FROM MyTable2 )
Instead of getting rows back how do I get a record count from the above query?
Thank you
All-Star
53091 Points
23659 Posts
Re: Help getting record count...
Feb 27, 2019 05:58 PM|mgebhard|LINK
See the SQL docs.
https://docs.microsoft.com/en-us/sql/t-sql/functions/count-transact-sql?view=sql-server-2017
Also, NOT IN can cause issues if there are NULL values in MyTable2.Acolumn1. A Join is better as it handles NULL as you likely expect.
https://docs.microsoft.com/en-us/sql/relational-databases/performance/joins?view=sql-server-2017