Free cookie consent management tool by TermsFeed Policy Generator
  • Azure SQL
  •    5 page views
  • 2024, June 14, Friday

#015 Return all rows and calculate the total value in Azure SQL

Como retornar todas as linhas e calcular o valor total em Consulta (SELECT) existente na linguagem de Manipulação de Dados (DML) do Azure SQL/SQL Server

This T-SQL code performs a query on the "f.Nota_Fiscal" table. I'll explain each part

of the code:SELECT [NUMBER], [
  1. QUANTITY] * [VALOR_UNITARIO], 'VERSION 1' AS CURRENT

    :
    • SELECT: Indicates that the next part of the code will specify which columns will be returned in the query.
    • [NUMBER]: Select the "NUMBER" column.
    • [QUANTITY]
    • * [VALOR_UNITARIO]: Calculates the product in the "QUANTITY" column by the value in the "VALOR_UNITARIO" column. The result doesn't have a specific name in the query (so it can be accessed by an unnamed expression).
    • 'VERSION 1'
    • AS CURRENT: Creates a column called 'CURRENT' that contains the string 'VERSION 1'. This column is added to each row of the query output.
  2. FROM [f].[ Nota_Fiscal]:

    • FROM: Indicates the table from which the data will be selected.
    • [f]. [Nota_Fiscal]: This is the name of the table from which the data will be extracted. The prefix "f." suggests that the table is in a schema called "f".

Therefore, the code returns three columns for each row of the "f.Nota_Fiscal" table:

  • The "NUMBER" column.
  • The result of the [QUANTITY] * [VALOR_UNITARIO] calculation.
  • A column named "CURRENT" with the value 'VERSION 1'.

This query is useful when you need to perform calculations or include constant values in your output. The result contains information related to the invoices present in the table, combining existing data and calculated/named values.

This content contains
  • Content Imagem
  • Language Portuguese
  • Duration
  • Subtitles Não

  • Reading time 1 min 14 seg

avatar
Fabio Santos

Data Scientist and Consultant for Digital and Analytics Solutions


  • Share

Youtube Channel

@fabioms

Subscribe now