Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

PI OLEDB Enterprise

USE statement

  • Last UpdatedSep 29, 2022
  • 1 minute read

The USE statement dynamically sets the default Catalog (PI AF database). It overwrites the Initial Catalog initialization property.

Syntax

USE database_name

Remarks

Because Catalog names are custom, the USE statement allows generalizing queries and making them portable to other systems or allows queries being used with different Catalogs (AF databases).

For example, the statement:

SELECT et.Name ElementTemplate
FROM NuGreen.Asset.Category c
INNER JOIN NuGreen.Asset.ElementTemplateCategory etc ON etc.CategoryID = c.ID
INNER JOIN NuGreen.Asset.ElementTemplate et ON et.ID = etc.ElementTemplateID
WHERE c.Name = N'Equipment Assets'

can be shortened to:

SELECT et.Name ElementTemplate
FROM Asset.Category c
INNER JOIN Asset.ElementTemplateCategory etc ON etc.CategoryID = c.ID
INNER JOIN Asset.ElementTemplate et ON et.ID = etc.ElementTemplateID
WHERE c.Name = N'Equipment Assets'

and because Asset is the default schema it can be even shorter:

SELECT et.Name ElementTemplate
FROM Category c
INNER JOIN ElementTemplateCategory etc ON etc.CategoryID = c.ID
INNER JOIN ElementTemplate et ON et.ID = etc.ElementTemplateID
WHERE c.Name = N'Equipment Assets'

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in