AugForums.com

An Acumatica User Group

  • Free
    • Start Here
    • Rolodex
    • Podcast
    • Blog
    • Forums
  • Paid
    • AugSQL
    • GI Course
    • GI Library
    • Consulting
  • Register
Acumatica Forums

By using this website, you agree to our Terms of Use (click here)

Forums
AugSQL
AugSQL
Your first SELECT s...
 
Notifications
Clear all

#AcumaticaTnT Your first SELECT statement and always using CompanyID

 
Votes Received: 0

AugSQL
Last Post by Tim Rodman 2 years ago
1 Posts
1 Users
0 Reactions
55 Views
RSS
Tim Rodman
Posts: 3193
 Tim Rodman
Admin
Topic starter
October 21, 2023 9:25 pm
(@timrodman)
Famed Member
Joined: 10 years ago

If you've never run a SQL statement before, then I've got a great place for you to start. You can start by running this SQL statement:

SELECT *
FROM Company
image

 

If that was your first SQL statement, then congratulations!

 

The reason why I like using the Company table in the first SQL statement is that it's great prep for pretty much every other SQL statement that you'll run.

Why? Because you should pretty much always include CompanyID (1, 2, 3 in the previous screenshot) when running a query to restrict the data returned to a specific Acumatica Tenant.

Wait, Tenant? Then why isn't it called TenantID instead of CompanyID?

 

Well, first we need to make sure that we're clear about what a Tenant is in Acumatica.

You can see the Tenant in the drop down on the login screen (1st screenshot) or in the upper right-hand corner of the screen after you've logged into Acumatica (2nd screenshot).

image
image

 

Why isn't it TenantID in the database? The Tenant in Acumatica used to be called Company, but they renamed it to Tenant in Acumatica 2018 R1. I noted it here:

https://www.augforums.com/forums/everything-else/instance-vs-tenant-vs-company-vs-branch

 

Even though Acumatica now calls it Tenant on the front-end, they never changed CompanyID to TenantID in the database because that would have been a major pain.

So, when you see CompanyID in the database, just think Tenant.

 

That matters because we always need to filter the results from a query by CompanyID so we only get the data from the Tenant that we're interested in.

Back in that first screenshot, there are 3 Companies (Tenants) listed:

  • 1 is the template Tenant. It contains template data like a list of Countries and States, Timezones, etc. So everyone's CompanyID of 1 has the same data.
  • 2 is the first Tenant in your Acumatica database. In my Acumatica demo environment, SalesDemo is the first Tenant listed.
  • 3 is the next Tenant. In my Acumatica demo environment, Another Tenant is the second Tenant listed.

 

So, if we want to see Customer data from the SalesDemo Tenant, then we need to filter on CompanyID=2 when querying the Customer table:

SELECT *
FROM Customer
WHERE CompanyID=2
image

 

Bottom line, make sure to filter on CompanyID when using AugSQL to query your Acumatica database.

Forum Jump:
  Previous Topic
Next Topic  
Forum Information
Recent Posts
Unread Posts
Tags
  • 12 Forums
  • 2,521 Topics
  • 10.9 K Posts
  • 10 Online
  • 2,321 Members
Our newest member: Courtney Wilder
Latest Post: Can UDFs be populated using an Import Scenario?
Forum Icons: Forum contains no unread posts Forum contains unread posts
Topic Icons: Not Replied Replied Active Hot Sticky Unapproved Solved Private Closed

Online Members

 No online members at the moment

Acumatica Forums

Terms of Use & Disclaimers :: Privacy Policy

Copyright © 2025 · AUG Forums, LLC. All rights reserved. This website is not owned, affiliated with, or endorsed by Acumatica, Inc.

‹›×

    ‹›×