Creating an SQL View

Create a view to query sources in a powerful SQL editor. You can choose between writing a standard SQL query using SELECT statements and operators such as JOIN and UNION, or use SQLScript to produce a table function. You can drag sources from the Source Browser, and specify measures and other aspects of your output structure in the side panel.

Prerequisites

To create views, you must have a scoped role that grants you access to a space with the following privileges:
  • Data Warehouse General (-R------) - To access SAP Datasphere.

  • Data Warehouse Data Builder (CRUD----) - To create, edit, and delete a graphical view.

  • Space Files (CRUD----) - To create, read, update, and delete objects in your spaces.

In addition, if you want to use AI features, they must be enabled in your tenant (see Enable SAP Business AI for SAP Datasphere) and you must have the following global privilege:
  • Data Warehouse AI Consumption (----E---) - To use SAP Business AI features.

The DW Modeler role template, for example, grants these scoped privileges and the DW AI Consumer global role grants the global privilege. For more information, see Privileges and Permissions and Standard Roles Delivered with SAP Datasphere.

Context

In this example, a view is created in which:
  • Various columns are selected from the Sales and Products entities and given aliases via the AS keyword.

  • A new, calculated column, Unit_Price is created using the ROUND() function.

  • The FROM clause defines an INNER JOIN between the entities on their Product_ID columns.

  • The WHERE clause filters the results by the Product_Line, which must be Electronics.

  • The ORDER BY clause orders the results by the value of Gross_Sales in descending order.

SELECT
  "Sales"."Date" AS "Date",
  "Products"."Product_ID" AS "Product_ID",
  "Products"."Line" AS "Product_Line",
  "Products"."Category" AS "Product_Category",
  "Products"."Product" AS "Product",
  ROUND("Sales"."Gross_Sales" / "Sales"."Quantity", 2) AS "Unit_Price",
  "Sales"."Gross_Sales" AS "Gross_Sales"
FROM ("Sales" INNER JOIN "Products" ON "Sales"."Product_ID" = "Products"."Product_ID")
WHERE "Products"."Product_Line" = "Electronics"
ORDER BY "Gross_Sales" DESC
If you are not comfortable with SQL, you can:

For information about making your data accessible outside SAP Datasphere, see Exposing Data For Consumption.

In addition to working with views in the editor, you can also:

Procedure

  1. In the side navigation area, select (Data Builder), select a space if necessary, and select New SQL View to open the editor.
  2. In the side panel, select the language that you want to use. You can choose between:
    • SQL (Standard Query) - [default] Create a standard SQL query, based around SELECT statements (see SQL Reference).

    • SQLScript (Table Function) - Use SQLScript with support for IF statements, loops, and other more complex structures (see SQLScript Reference).

  3. Enter your code in the editor panel. You can:
    • Access auto-complete suggestions for keywords and object names including source entities by typing.

    • Drag sources from the Source Browser into the editor panel.

    • Add comments to document your code:

      • Comment out a single line or the rest of a line with a double dash: -- Your comment here.

      • Comment out multiple lines or part of a line with: /* Your comment here */.

      This example contains various forms of comments:

      /*  
          This is a multi-line comment to
          introduce this view 
      */
      
      SELECT "ID",
      	"Date",
      --	"Sales Person", comment out a line
      	"City", -- comment at end of line
      	"Net Sales"
      FROM /* mid-line comment */ "Sales"
    • Format your SQL code by clicking Format.

    • Validate your code and update the display of your output structure in the side panel at any time by clicking (Validate SQL and Preview Data).

      SQL errors and warnings are shown in the Errors pane at the bottom of the editor. Problems with the output structure are shown on the Validation Messages button in the side panel header.
    • Preview the data being output by the view by clicking (Show or hide data preview)(see Viewing Object Data).

      You cannot view data in an SQL view if any of its sources is shared from another space and has an input parameter.

  4. Enter the following properties as appropriate in the side panel:

    Property

    Description

    Business Name

    Enter a descriptive name to help users identify the object. This name can be changed at any time.

    Technical Name

    Displays the name used in scripts and code, synchronized by default with the Business Name.

    To override the default technical name, enter a new one in the field. Technical names can contain only alphanumeric characters and underscores.

    Package

    Select the package to which the object belongs.

    Packages are used to group related objects in order to facilitate their transport between tenants. For more information, see Creating Packages to Export.

    Release State

    Specifies whether the object is released, providing modelers and consumers with confidence that it will remain available in its current form for the foreseeable future.

    For more information, see Releasing Stable Views for Consumption.

    Language

    Select the SQL language to use.

    Choose from the following:
    • SQL (Standard Query) - [default] Create a standard SQL query, based around SELECT statements (see SQL Reference).

    • SQLScript (Table Function) - Use SQLScript with support for IF statements, loops, and other more complex structures (see SQLScript Reference).

    Source Object (Open SQL Schema/HDI Container)

    [read-only] Displays the technical name of the Open SQL Schema or HDI Container and the object name.

    Semantic Usage

    Select the way your entity should be used for data modeling purposes.

    Choose from the following:

    Dimension Type

    [dimensions only] Select whether your dimension is Standard or Fiscal Time.

    For Fiscal Time dimensions, see Create a Fiscal Time Dimension.

    Expose for Consumption

    Enable this option to make the view available for consumption outside SAP Datasphere via OData or ODBC/JDBC.

    This option is not required if you want to expose your data through an analytic model (see Creating an Analytic Model). For an overview about making your data accessible outside SAP Datasphere, see Exposing Data For Consumption.

    Run in Analytical Mode

    Enable this option to send the USE_OLAP_PLAN hint to the SQL optimizer.

    This may improve view performance, particularly if a union is performed. It is only available if Expose for Consumption is enabled.

    For more information, see HINT Details in the SAP HANA Cloud, SAP HANA Database SQL Reference Guide.

    Status

    [read-only] Displays the deployment and error status of the object.

    For more information, see Saving and Deploying Objects.

    Deployed On

    [read-only] Displays the date and time of the last deployment.

    Data Validation Status

    Displays the status of the last data validation.

    Click the button to open the Data Validation panel (see Validating View Data).

    Validated On

    [read-only] Displays the date and time of the last data validation.

  5. Based on the Semantic Usage of your entity, review and modify its Columns, Attributes, and/or Measures:
  6. Complete or consult other sections as appropriate:
  7. Click (Save)Start of the navigation path Next navigation step SaveEnd of the navigation path to save your entity or click (Deploy) to save and deploy it immediately.
    For more information, see Saving and Deploying Objects.
  8. The tools in the editor toolbar help you work with your object throughout its lifecycle:

    Tool

    Description

    (Save)

    Save your changes to the design-time repository. You can use Save As to create a copy of the object.

    See Saving and Deploying Objects.

    (Deploy)

    Deploy your changes to make them available in the run-time environment.

    See Saving and Deploying Objects.

    (Share)

    Share the object to other spaces.

    See Sharing Entities and Task Chains to Other Spaces.

    (Source Browser)

    Show the Source Browser panel to drag sources into the editor.

    See Using the Source Browser.

    (Preview Data)

    Open the Data Preview panel to preview the data output by the view.

    See Viewing Object Data.

    (Export)

    Export the object to a CSN/JSON file.

    See Exporting Objects to a CSN/JSON File.

    (Edit Custom CSN Annotations)

    Work with custom CSN annotations that are not otherwise supported by the interface.

    See Edit Custom CSN Annotations in a View or Table.

    (Impact and Lineage Analysis)

    Open the Impact and Lineage Analysis graph for the object.

    See Impact and Lineage Analysis.

    (Generate OData Request)

    Open the Generate OData Request dialog to prepare access to the OData API.

    See Consuming Data via the OData API.

    (Runtime Metrics)

    Open the Runtime Metrics tool to analyze the performance of your view. This tool also provides the option to directly generate and download an Explain Plan or execute View Analyzer to improve your view performance.

    See Analyzing View Performance.

    (Generate)

    Open the AI-assisted generation menu:

    Versions

    Open the Version History dialog for the object.

    See Reviewing and Restoring Object Versions.

    Details

    Toggles the display of the Properties panel.

    (Open Data Pipeline Analyzer)

    The Data Pipeline Analyzer helps you view and analyze errors, warnings, or data discrepancies for a selected object, so that you can understand the point of data transfer failure. This tool is useful for identifying and resolving data transfer failures, ensuring efficient data flow management and troubleshooting within complex data models. See Data Pipeline Analyzer