-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.ps1
More file actions
47 lines (39 loc) · 1.14 KB
/
Test.ps1
File metadata and controls
47 lines (39 loc) · 1.14 KB
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
Clear-Host
[string] $script = @'
WITH cte_sales_amounts (staff, sales, year) AS (
SELECT
first_name + ' ' + last_name,
SUM(quantity * list_price * (1 - discount)),
YEAR(order_date)
FROM
sales.orders o
INNER JOIN sales.order_items i ON i.order_id = o.order_id
INNER JOIN sales.staffs s ON s.staff_id = o.staff_id
GROUP BY
first_name + ' ' + last_name,
year(order_date)
)
SELECT
staff,
sales
FROM
cte_sales_amounts
WHERE
year = 2018;
'@
try {
. $PSScriptRoot\Get-TSqlAbstractSyntaxTree.ps1
[xml]$result = Get-TSqlAbstractSyntaxTree -SqlServerVersion 2017 -ScriptDomLocation 'C:\Temp\' -Script $script -PositionalProperties $false
}
catch {
throw $_
break
}
$StringWriter = New-Object System.IO.StringWriter
$XmlWriter = New-Object -TypeName System.XMl.XmlTextWriter -ArgumentList $StringWriter
$XmlWriter.Formatting = 'indented'
$XmlWriter.Indentation = 2
$result.WriteContentTo($XmlWriter)
$XmlWriter.Flush()
$StringWriter.Flush()
Write-Host $stringWriter.ToString()