Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| tech-notes:sql [2021/05/14 11:39] – [6 Digit Random Number] gerardorourke | tech-notes:sql [2022/12/21 14:06] (current) – [SUBSTRING and CHARINDEX] gerardorourke | ||
|---|---|---|---|
| Line 34: | Line 34: | ||
| as MaxIncomePerDay | as MaxIncomePerDay | ||
| where VendorId in (' | where VendorId in (' | ||
| + | </ | ||
| + | |||
| + | ===== DateTime ===== | ||
| + | ====Convert DateTime to Just Date==== | ||
| + | <code sql> | ||
| + | CONVERT(Datetime, | ||
| + | </ | ||
| + | |||
| + | ====Convert DateTime to Date + Hour==== | ||
| + | <code sql> | ||
| + | Date = DATEADD(hour, | ||
| + | </ | ||
| + | |||
| + | ====Convert DateTime to Just the Year==== | ||
| + | < | ||
| + | |||
| + | ====Convert DateTime to Just the Month==== | ||
| + | < | ||
| + | |||
| + | ====Convert DateTime to the week ==== | ||
| + | < | ||
| + | CASE WHEN DATEPART(week, | ||
| + | THEN DATEADD(day, | ||
| + | ELSE DATEADD(day, | ||
| </ | </ | ||
| Line 53: | Line 77: | ||
| ==CONVERT== | ==CONVERT== | ||
| http:// | http:// | ||
| - | |||
| - | ==Convert DateTime to Just Date== | ||
| - | <code sql> | ||
| - | CONVERT(Datetime, | ||
| - | </ | ||
| - | |||
| - | ==Convert DateTime to Date + Hour== | ||
| - | <code sql> | ||
| - | Date = DATEADD(hour, | ||
| - | </ | ||
| Line 294: | Line 308: | ||
| *https:// | *https:// | ||
| + | |||
| + | ===== SUBSTRING and CHARINDEX ===== | ||
| + | |||
| + | Here we have a column ' | ||
| + | < | ||
| + | [FirstVariable] = SUBSTRING([myColumn], | ||
| + | [SecondVariable] = SUBSTRING([myColumn], | ||
| + | </ | ||
| + | |||
| + | CHARINDEX find the comma and lets you know the position it is in. | ||
| + | SUBSTRING uses start and end position to extract a substring. | ||