\n
MSSQL cheat sheet
\n Time series:\n
\n - \n return column named time (in UTC), as a unix time stamp or any sql native date data type. You can use the\n macros below.\n
\n - any other columns returned will be the time point values.
\n
\n Optional:\n
\n - \n return column named metric to represent the series name.\n
\n - If multiple value columns are returned the metric column is used as prefix.
\n - If no column named metric is found the column name of the value column is used as series name
\n
\n
Resultsets of time series queries need to be sorted by time.
\n Table:\n
\n - return any set of columns
\n
\n Macros:\n
\n - $__time(column) -> column AS time
\n - $__timeEpoch(column) -> DATEDIFF(second, '1970-01-01', column) AS time
\n - \n $__timeFilter(column) -> column BETWEEN '2017-04-21T05:01:17Z' AND\n '2017-04-21T05:01:17Z'\n
\n - $__unixEpochFilter(column) -> column >= 1492750877 AND column <= 1492750877
\n - \n $__unixEpochNanoFilter(column) -> column >= 1494410783152415214 AND column <= 1494497183142514872\n
\n - \n $__timeGroup(column, '5m'[, fillvalue]) -> CAST(ROUND(DATEDIFF(second, '1970-01-01',\n column)/300.0, 0) as bigint)*300 by setting fillvalue grafana will fill in missing values according to the\n interval fillvalue can be either a literal value, NULL or previous; previous will fill in the previous seen\n value or NULL if none has been seen yet\n
\n - \n $__timeGroupAlias(column, '5m'[, fillvalue]) -> CAST(ROUND(DATEDIFF(second,\n '1970-01-01', column)/300.0, 0) as bigint)*300 AS [time]\n
\n - $__unixEpochGroup(column,'5m') -> FLOOR(column/300)*300
\n - $__unixEpochGroupAlias(column,'5m') -> FLOOR(column/300)*300 AS [time]
\n
\n
Example of group by and order by with $__timeGroup:
\n
\n \n SELECT $__timeGroup(date_time_col, '1h') AS time, sum(value) as value
\n FROM yourtable\n
\n GROUP BY $__timeGroup(date_time_col, '1h')\n
\n ORDER BY 1\n
\n
\n
\n Or build your own conditionals using these macros which just return the values:\n
\n - $__timeFrom() -> '2017-04-21T05:01:17Z'
\n - $__timeTo() -> '2017-04-21T05:01:17Z'
\n - $__unixEpochFrom() -> 1492750877
\n - $__unixEpochTo() -> 1492750877
\n - $__unixEpochNanoFrom() -> 1494410783152415214
\n - $__unixEpochNanoTo() -> 1494497183142514872
\n
\n
\n );\n}\n\nfunction getStyles(theme: GrafanaTheme2) {\n return {\n ulPadding: css({\n margin: theme.spacing(1, 0),\n paddingLeft: theme.spacing(5),\n }),\n };\n}\n","import { DataSourceJsonData } from '@grafana/data';\nimport { SQLOptions } from '@grafana/sql';\nimport { HttpSettingsBaseProps } from '@grafana/ui/src/components/DataSourceSettings/types';\n\nexport enum MSSQLAuthenticationType {\n sqlAuth = 'SQL Server Authentication',\n windowsAuth = 'Windows Authentication',\n azureAuth = 'Azure AD Authentication',\n}\n\nexport enum MSSQLEncryptOptions {\n disable = 'disable',\n false = 'false',\n true = 'true',\n}\n\nexport enum AzureCloud {\n Public = 'AzureCloud',\n None = '',\n}\n\nexport type ConcealedSecretType = symbol;\n\nexport enum AzureAuthType {\n MSI = 'msi',\n CLIENT_SECRET = 'clientsecret',\n}\n\nexport interface AzureCredentialsType {\n authType: AzureAuthType;\n azureCloud?: string;\n tenantId?: string;\n clientId?: string;\n clientSecret?: string | ConcealedSecretType;\n}\n\nexport interface MssqlOptions extends SQLOptions {\n authenticationType?: MSSQLAuthenticationType;\n encrypt?: MSSQLEncryptOptions;\n sslRootCertFile?: string;\n serverName?: string;\n connectionTimeout?: number;\n azureCredentials?: AzureCredentialsType;\n}\n\nexport interface MssqlSecureOptions {\n password?: string;\n}\n\nexport type AzureAuthJSONDataType = DataSourceJsonData & {\n azureCredentials: AzureCredentialsType;\n};\n\nexport type AzureAuthSecureJSONDataType = {\n azureClientSecret: undefined | string | ConcealedSecretType;\n};\n\nexport type AzureAuthConfigType = {\n azureAuthIsSupported: boolean;\n azureAuthSettingsUI: (props: HttpSettingsBaseProps) => JSX.Element;\n};\n","import { SelectableValue } from '@grafana/data';\n\nimport { AzureCredentialsType, AzureAuthType } from '../types';\n\nexport enum AzureCloud {\n Public = 'AzureCloud',\n None = '',\n}\n\nexport const KnownAzureClouds: Array