40b60bdefb76f52c4bf2939a19ea71be95601d14
Integration/Tutorials/Views.md
| ... | ... | @@ -46,8 +46,8 @@ CREATE VIEW Persons AS SELECT ctx_fname AS FirstName, ctx_lname AS LastName FRO |
| 46 | 46 | ``` sql |
| 47 | 47 | CREATE VIEW Events AS |
| 48 | 48 | SELECT CASE DATEPART(w,CreateDate) |
| 49 | - WHEN ‘1’ THEN ‘Sunday’ |
|
| 50 | - WHEN ‘2’ THEN ‘Monday’ |
|
| 49 | + WHEN '1' THEN 'Sunday' |
|
| 50 | + WHEN '2' THEN 'Monday' |
|
| 51 | 51 | END AS DayOfWeekAggregating Data |
| 52 | 52 | CREATE VIEW OrderSummary |
| 53 | 53 | SELECT DATEPART(yyyy,OrderDate) AS OrderMonth |
| ... | ... | @@ -94,8 +94,8 @@ UNION SELECT emp_name |
| 94 | 94 | ``` sql |
| 95 | 95 | CREATE VIEW Events AS |
| 96 | 96 | SELECT CASE DATEPART(w,CreateDate) |
| 97 | - WHEN ‘1’ THEN ‘Sunday’ |
|
| 98 | - WHEN ‘2’ THEN ‘Monday’ |
|
| 97 | + WHEN '1' THEN 'Sunday' |
|
| 98 | + WHEN '2' THEN 'Monday' |
|
| 99 | 99 | END AS DayOfWeekAggregating Data |
| 100 | 100 | |
| 101 | 101 | CREATE VIEW OrderSummary |
| ... | ... | @@ -165,4 +165,14 @@ SELECT [ShipCountry],SUM(Freight) AS Total,SUM(CASE DATEPART(yyyy,[OrderDate]) |
| 165 | 165 | WHEN '2008' THEN Freight ELSE 0 END) AS [2008] |
| 166 | 166 | FROM [Orders] |
| 167 | 167 | GROUP BY [ShipCountry] |
| 168 | +``` |
|
| 169 | + |
|
| 170 | +**Organizing Dates by Week** |
|
| 171 | + |
|
| 172 | +The following example illustrates how to create a view that will convert a date field into the week number. |
|
| 173 | + |
|
| 174 | +```sql |
|
| 175 | +CREATE VIEW WeekView AS |
|
| 176 | +SELECT DATENAME(week, [dbo].[Orders].[OrderDate]) AS Week, OrderID |
|
| 177 | +FROM [dbo].[Orders] |
|
| 168 | 178 | ``` |
| ... | ... | \ No newline at end of file |