Integration.md
... ...
@@ -1 +1,32 @@
1
-Please re-purpose this page.
... ...
\ No newline at end of file
0
+#Combining Multiple Event Based Fields with UNION
1
+
2
+[[_TOC_]]
3
+
4
+##About
5
+Event-based or time-series data is often spread across multiple fields or data sources which makes it difficult to report on. The UNION operator may be used to combine these fields into one and create an artificial categorical field which defines the type of event it is.
6
+
7
+##Method 1
8
+
9
+```sql
10
+CREATE VIEW EventView AS
11
+SELECT OrderDate AS Date, 'Order' AS Event, ShipCountry AS Country FROM
12
+Orders UNION
13
+SELECT ShippedDate AS Date, 'Shipment' AS Event, ShipCountry AS Country
14
+FROM Orders UNION
15
+SELECT HireDate AS Date, 'Hire' AS Event, Country AS Country
16
+FROM Employees
17
+```
18
+
19
+##Method 2
20
+
21
+Additionally, an outer query may be used to further simplify the results of the UNION
22
+
23
+```sql
24
+CREATE VIEW EventView AS
25
+SELECT DatePart(m,Date) as Month, DatePart(yyyy,Date) as YEAR, * FROM
26
+(
27
+SELECT OrderDate AS Date, 'Order' AS Event, ShipCountry AS Country FROM Orders UNION
28
+SELECT ShippedDate AS Date, 'Shipment' AS Event, ShipCountry AS Country FROM Orders UNION
29
+SELECT HireDate AS Date, 'Hire' AS Event, Country AS Country FROM Employees
30
+) AS IQ
31
+```
... ...
\ No newline at end of file