-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09.Variável.sql
More file actions
51 lines (32 loc) · 907 Bytes
/
09.Variável.sql
File metadata and controls
51 lines (32 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
--VARIAVEL
--Declate com uma variável
DECLARE @Criancas INT =3
SELECT
CustomerKey,
FirstName,
NumberChildrenAtHome
FROM DimCustomer
WHERE NumberChildrenAtHome = @Criancas
--Declate com mais variáveis
DECLARE @Crianca2 INT = 3,
@Genero VARCHAR(1) = 'F'
SELECT
*
FROM DimCustomer
WHERE NumberChildrenAtHome = @Crianca2 AND Gender = @Genero
-- Inserir o resultad de um select em uma variável
DECLARE @LojasOff INT
SET @LojasOff = (
SELECT COUNT(*)
FROM DimStore
WHERE Status = 'Off')
select @LojasOff as 'Lojas_Off'
-- Inserir uma valor em uma variavel e visualizar junto a outra tabela
DECLARE @ProdutoMaisVendido INT
SELECT TOP (1) @ProdutoMaisVendido = ProductKey
FROM FactSales
ORDER BY SalesQuantity DESC
--SELECT @ProdutoMaisVendido
SELECT ProductKey,ProductName
FROM DimProduct
WHERE ProductKey = @ProdutoMaisVendido -- SELECIONA O PRODUTO MAIS VENDIDO JUNTO A OUTRA TABELA