<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Microsoft SQL Server data source on Grafana Labs</title><link>https://grafana.com/docs/grafana/v13.2/datasources/mssql/</link><description>Recent content in Microsoft SQL Server data source on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/grafana/v13.2/datasources/mssql/index.xml" rel="self" type="application/rss+xml"/><item><title>Configure the Microsoft SQL Server data source</title><link>https://grafana.com/docs/grafana/v13.2/datasources/mssql/configure/</link><pubDate>Tue, 18 Aug 2026 10:15:08 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.2/datasources/mssql/configure/</guid><content><![CDATA[&lt;h1 id=&#34;configure-the-microsoft-sql-server-data-source&#34;&gt;Configure the Microsoft SQL Server data source&lt;/h1&gt;
&lt;p&gt;This document provides instructions for configuring the Microsoft SQL Server data source and explains available configuration options. For general information on adding and managing data sources, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/&#34;&gt;Grafana data sources&lt;/a&gt; and 
    &lt;a href=&#34;/docs/grafana/v13.2/administration/data-source-management/&#34;&gt;Data source management&lt;/a&gt;.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;This page documents the &lt;strong&gt;Microsoft SQL Server data source&lt;/strong&gt;, which lets you query an existing SQL Server database and visualize the results in Grafana. This is different from the &lt;a href=&#34;/docs/grafana-cloud/monitor-infrastructure/integrations/integration-reference/integration-mssql/&#34;&gt;Microsoft SQL Server integration&lt;/a&gt; (available in Grafana Cloud), which uses Grafana Alloy to collect performance metrics &lt;em&gt;about&lt;/em&gt; your SQL Server instance (CPU, memory, connections, and similar). If you want to monitor the health of SQL Server itself, refer to the integration documentation instead.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;Before configuring the Microsoft SQL Server data source, ensure you have the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Grafana permissions:&lt;/strong&gt; You must have the &lt;code&gt;Organization administrator&lt;/code&gt; role to add and configure data sources. Users with the &lt;code&gt;Editor&lt;/code&gt; or &lt;code&gt;Viewer&lt;/code&gt; role cannot access the data source configuration form unless granted additional permissions through 
    &lt;a href=&#34;/docs/grafana/v13.2/administration/roles-and-permissions/access-control/&#34;&gt;RBAC&lt;/a&gt;. Organization administrators can also &lt;a href=&#34;#provision-the-data-source&#34;&gt;configure the data source via YAML&lt;/a&gt; with the Grafana provisioning system.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;A running SQL Server instance:&lt;/strong&gt; Microsoft SQL Server 2012 or newer, Azure SQL Database, or Azure SQL Managed Instance.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Network access:&lt;/strong&gt; Grafana must be able to reach your SQL Server. The default port is &lt;code&gt;1433&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Authentication credentials:&lt;/strong&gt; Depending on your authentication method, you need one of:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;SQL Server login credentials (username and password).&lt;/li&gt;
&lt;li&gt;Windows/Kerberos credentials and configuration (not supported in Grafana Cloud).&lt;/li&gt;
&lt;li&gt;Azure Entra ID app registration or managed identity.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Security certificates:&lt;/strong&gt; If using encrypted connections, gather any necessary TLS/SSL certificates.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Grafana ships with a built-in Microsoft SQL Server data source plugin. No additional installation is required.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;



&lt;div class=&#34;admonition admonition-tip&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Tip&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Grafana Cloud users:&lt;/strong&gt; If your SQL Server is in a private network, you can configure &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;Private data source connect&lt;/a&gt; to establish connectivity.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;add-the-mssql-data-source&#34;&gt;Add the MSSQL data source&lt;/h2&gt;
&lt;p&gt;To add the MSSQL data source, complete the following steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Click &lt;strong&gt;Connections&lt;/strong&gt; in the left-side menu.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add new connection&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Type &lt;code&gt;Microsoft SQL Server&lt;/code&gt; in the search bar.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Microsoft SQL Server&lt;/strong&gt; under data source.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add new data source&lt;/strong&gt; in the upper right.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Grafana takes you to the &lt;strong&gt;Settings&lt;/strong&gt; tab, where you will set up your Microsoft SQL Server configuration.&lt;/p&gt;
&lt;h2 id=&#34;configure-the-data-source-in-the-ui&#34;&gt;Configure the data source in the UI&lt;/h2&gt;
&lt;p&gt;Following are configuration options for the Microsoft SQL Server data source.&lt;/p&gt;
&lt;!-- vale Grafana.Spelling = NO --&gt;


&lt;div class=&#34;admonition admonition-warning&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Warning&lt;/p&gt;&lt;p&gt;Kerberos is not supported in Grafana Cloud.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;!-- vale Grafana.Spelling = YES --&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;&lt;strong&gt;Setting&lt;/strong&gt;&lt;/th&gt;
              &lt;th&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The data source name. Sets the name you use to refer to the data source in panels and queries. Examples: &lt;code&gt;MSSQL-1&lt;/code&gt;, &lt;code&gt;MSSQL_Sales1&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Default&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Toggle to select as the default name in dashboard panels. When you go to a dashboard panel, this will be the default selected data source.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;&lt;strong&gt;Connection:&lt;/strong&gt;&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Setting&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Host&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Sets the IP address or hostname (and optional port) of your MSSQL instance. The default port is &lt;code&gt;0&lt;/code&gt;, which uses the driver&amp;rsquo;s default. You can include additional connection properties (for example, &lt;code&gt;ApplicationIntent&lt;/code&gt;) by separating them with semicolons (&lt;code&gt;;&lt;/code&gt;).&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Database&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Sets the name of the MSSQL database to connect to.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;

&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;If you add &lt;code&gt;ApplicationIntent=ReadOnly&lt;/code&gt; to the Host field to route queries to a read-only replica, be aware that read-only replicas may be significantly slower than the primary. This can cause dashboard load times of several minutes. Only use &lt;code&gt;ApplicationIntent=ReadOnly&lt;/code&gt; if your replica is sized for the query workload and you&amp;rsquo;ve tested performance.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;TLS/SSL encryption:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;Encrypt&lt;/strong&gt; setting determines whether and to what extent a secure TLS/SSL connection is negotiated with the server.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Encrypt setting&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
              &lt;th&gt;When to use&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Disable&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Data sent between the client and server is &lt;strong&gt;not encrypted&lt;/strong&gt;.&lt;/td&gt;
              &lt;td&gt;Legacy environments where encryption isn&amp;rsquo;t supported or required. Not recommended for production.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;False&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The default setting. Only the login packet is encrypted; &lt;strong&gt;all other data is sent unencrypted&lt;/strong&gt;.&lt;/td&gt;
              &lt;td&gt;Development environments or when SQL Server doesn&amp;rsquo;t have a valid certificate.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;True&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;All data&lt;/strong&gt; sent between the client and server is &lt;strong&gt;encrypted&lt;/strong&gt;.&lt;/td&gt;
              &lt;td&gt;Production environments. Required for Azure SQL Database.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;When &lt;strong&gt;Encrypt&lt;/strong&gt; is set to &lt;strong&gt;True&lt;/strong&gt;, the following additional TLS options are available:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Setting&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
              &lt;th&gt;Default&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Skip TLS Verify&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;If enabled, the server&amp;rsquo;s certificate chain and hostname aren&amp;rsquo;t validated. Equivalent to &lt;code&gt;trustServerCertificate=true&lt;/code&gt; in the connection string.&lt;/td&gt;
              &lt;td&gt;Disabled&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;TLS/SSL Root Certificate&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Path to a PEM-encoded CA certificate file used to verify the server&amp;rsquo;s certificate. Required when the SQL Server uses a certificate signed by a private CA.&lt;/td&gt;
              &lt;td&gt;System CA bundle&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Hostname in server certificate&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The expected hostname in the server&amp;rsquo;s TLS certificate. Use this when the certificate&amp;rsquo;s Common Name (CN) or Subject Alternative Name (SAN) doesn&amp;rsquo;t match the configured hostname (for example, when connecting through a load balancer or PDC).&lt;/td&gt;
              &lt;td&gt;Value from &lt;strong&gt;Host&lt;/strong&gt; field&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;&lt;strong&gt;Choosing the right encryption configuration:&lt;/strong&gt;&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Scenario&lt;/th&gt;
              &lt;th&gt;Encrypt&lt;/th&gt;
              &lt;th&gt;Skip TLS Verify&lt;/th&gt;
              &lt;th&gt;Root Certificate&lt;/th&gt;
              &lt;th&gt;Notes&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Azure SQL Database&lt;/td&gt;
              &lt;td&gt;True&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;Not needed&lt;/td&gt;
              &lt;td&gt;Azure SQL always requires encryption and uses a publicly trusted certificate.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;SQL Server with public CA certificate&lt;/td&gt;
              &lt;td&gt;True&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;Not needed&lt;/td&gt;
              &lt;td&gt;Certificate is already in the system trust store.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;SQL Server with private/self-signed certificate&lt;/td&gt;
              &lt;td&gt;True&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;Path to CA cert&lt;/td&gt;
              &lt;td&gt;Upload or reference the CA certificate that signed the SQL Server certificate.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;SQL Server with unverified certificate (testing only)&lt;/td&gt;
              &lt;td&gt;True&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
              &lt;td&gt;Not needed&lt;/td&gt;
              &lt;td&gt;Skips certificate validation entirely. Don&amp;rsquo;t use in production.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;SQL Server 2008/2008R2 without valid certificate&lt;/td&gt;
              &lt;td&gt;Disable or False&lt;/td&gt;
              &lt;td&gt;N/A&lt;/td&gt;
              &lt;td&gt;N/A&lt;/td&gt;
              &lt;td&gt;Older versions may not support TLS negotiation.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Grafana Cloud with PDC&lt;/td&gt;
              &lt;td&gt;True&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;Not needed (usually)&lt;/td&gt;
              &lt;td&gt;PDC tunnels are encrypted at the SSH layer; the TLS certificate must still be valid from the PDC agent&amp;rsquo;s perspective.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;

&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;If you&amp;rsquo;re using an older version of Microsoft SQL Server like 2008 or 2008R2, you may need to set Encrypt to &lt;strong&gt;Disable&lt;/strong&gt; or &lt;strong&gt;False&lt;/strong&gt; to connect.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;



&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;Grafana builds using BoringCrypto (FIPS-compliant builds) enforce FIPS 140-3 cipher requirements. If your SQL Server only supports older cipher suites (for example, TLS 1.0 or RC4-based ciphers), connections from a FIPS-enabled Grafana instance fail with a TLS handshake error. Upgrade your SQL Server TLS configuration to support TLS 1.2 with FIPS-approved cipher suites.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Authentication:&lt;/strong&gt;&lt;/p&gt;
&lt;!-- vale Grafana.Spelling = NO --&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Authentication Type&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
              &lt;th&gt;Credentials / Fields&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;SQL Server Authentication&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Default method to connect to MSSQL. Use a SQL Server or Windows login in &lt;code&gt;DOMAIN\User&lt;/code&gt; format.&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;Username&lt;/strong&gt;: SQL Server username. &lt;strong&gt;Password&lt;/strong&gt;: SQL Server password.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Windows Authentication&lt;/strong&gt; (Integrated Security)&lt;/td&gt;
              &lt;td&gt;Uses the logged-in Windows user&amp;rsquo;s credentials via single sign-on. Available only when SQL Server allows Windows Authentication.&lt;/td&gt;
              &lt;td&gt;No input required; uses the logged-in Windows user&amp;rsquo;s credentials.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Windows AD&lt;/strong&gt; (Username/Password)&lt;/td&gt;
              &lt;td&gt;Authenticates a domain user with their Active Directory username and password.&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;Username&lt;/strong&gt;: &lt;code&gt;user@example.com&lt;/code&gt;. &lt;strong&gt;Password&lt;/strong&gt;: Active Directory password.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Windows AD&lt;/strong&gt; (Keytab)&lt;/td&gt;
              &lt;td&gt;Authenticates a domain user using a keytab file.&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;Username&lt;/strong&gt;: &lt;code&gt;user@example.com&lt;/code&gt;. &lt;strong&gt;Keytab file path&lt;/strong&gt;: Path to your keytab file.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Windows AD&lt;/strong&gt; (Credential Cache)&lt;/td&gt;
              &lt;td&gt;Uses a Kerberos credential cache already loaded in memory (for example, from a prior &lt;code&gt;kinit&lt;/code&gt; command). No file needed.&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;Credential cache path&lt;/strong&gt;: Path to in-memory credential (for example, &lt;code&gt;/tmp/krb5cc_1000&lt;/code&gt;).&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Windows AD&lt;/strong&gt; (Credential Cache File)&lt;/td&gt;
              &lt;td&gt;Authenticates a domain user using a credential cache file (&lt;code&gt;.ccache&lt;/code&gt;).&lt;/td&gt;
              &lt;td&gt;&lt;strong&gt;Username&lt;/strong&gt;: &lt;code&gt;user@example.com&lt;/code&gt;. &lt;strong&gt;Credential cache file path&lt;/strong&gt;: for example, &lt;code&gt;/home/grot/cache.json&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Azure Entra ID (formerly Azure AD) Authentication&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Authenticates the data source using Azure authentication methods.&lt;/td&gt;
              &lt;td&gt;Details on the supported authentication methods and how to configure them can be found in the &lt;a href=&#34;./index.md#azure-entra-id-formerly-azure-ad-authentication&#34;&gt;Azure authentication section&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;!-- vale Grafana.Spelling = YES --&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;As of Grafana v13.0, passwords and usernames that contain semicolons (&lt;code&gt;;&lt;/code&gt;) or closing braces (&lt;code&gt;}&lt;/code&gt;) are handled correctly. If you previously encountered connection failures due to special characters in credentials, upgrade to Grafana v13.0 or later.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Additional settings:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Additional settings are optional settings you configure for more control over your data source. This includes connection limits, connection timeout, group-by time interval, and Secure Socks Proxy.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Connection limits:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Grafana maintains a connection pool for each configured MSSQL data source. These settings control pool behavior and directly affect performance, especially under concurrent load from dashboards and alerting.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Setting&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Max open&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The maximum number of open connections to the database. If set to &lt;code&gt;0&lt;/code&gt;, there is no limit. If &lt;code&gt;max open&lt;/code&gt; is greater than &lt;code&gt;0&lt;/code&gt; and less than &lt;code&gt;max idle&lt;/code&gt;, &lt;code&gt;max idle&lt;/code&gt; is adjusted to match.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Auto max idle&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;When enabled, automatically sets &lt;code&gt;max idle&lt;/code&gt; to match &lt;code&gt;max open&lt;/code&gt;. If &lt;code&gt;max open&lt;/code&gt; isn’t set, it defaults to &lt;code&gt;100&lt;/code&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Max idle&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The maximum number of idle connections in the pool. If &lt;code&gt;max open&lt;/code&gt; is set and is lower than &lt;code&gt;max idle&lt;/code&gt;, then &lt;code&gt;max idle&lt;/code&gt; is reduced to match. If set to &lt;code&gt;0&lt;/code&gt;, no idle connections are retained.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Max lifetime&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;The maximum time (in seconds) a connection can be reused before being closed and replaced. If set to &lt;code&gt;0&lt;/code&gt;, connections are reused indefinitely.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;

&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;If &lt;strong&gt;Max open&lt;/strong&gt; is set too low, concurrent dashboard panels and alert rule evaluations compete for connections. Alerting queries may fail with &amp;ldquo;failed to connect to server&amp;rdquo; while dashboards continue to work, because alert evaluations use a separate execution path that can&amp;rsquo;t wait indefinitely for a free connection. Increase &lt;strong&gt;Max open&lt;/strong&gt; if you see intermittent alert failures.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Connection details:&lt;/strong&gt;&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;&lt;strong&gt;Setting&lt;/strong&gt;&lt;/th&gt;
              &lt;th&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Min time interval&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Specifies the lower bound for the auto-generated &lt;code&gt;GROUP BY&lt;/code&gt; time interval. Grafana recommends matching this value to the data write frequency—for example, &lt;code&gt;1m&lt;/code&gt; if data is written every minute. Refer to &lt;a href=&#34;#min-time-interval&#34;&gt;Min time interval&lt;/a&gt; for details.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;Connection timeout&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Specifies the maximum number of seconds to wait when attempting to connect to the database before timing out. A value of &lt;code&gt;0&lt;/code&gt; (the default) disables the timeout.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;&lt;strong&gt;Windows AD Advanced settings:&lt;/strong&gt;&lt;/p&gt;
&lt;!-- vale Grafana.Spelling = NO --&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Setting&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
              &lt;th&gt;Default&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;UDP Preference Limit&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Defines the maximum packet size (in bytes) that Kerberos libraries attempt to send over UDP before retrying with TCP. A value of &lt;code&gt;1&lt;/code&gt; forces all communication to use TCP.&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;1&lt;/code&gt; (always use TCP)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;DNS Lookup KDC&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Controls whether DNS &lt;code&gt;SRV&lt;/code&gt; records are used to locate &lt;a href=&#34;https://web.mit.edu/kerberos/krb5-latest/doc/admin/realm_config.html#key-distribution-centers&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Key Distribution Centers (KDCs)&lt;/a&gt; and other servers for the realm.&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;true&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;strong&gt;krb5 config file path&lt;/strong&gt;&lt;/td&gt;
              &lt;td&gt;Specifies the path to the Kerberos configuration file used by the &lt;a href=&#34;https://web.mit.edu/kerberos/krb5-1.12/doc/admin/conf_files/krb5_conf.html&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;MIT krb5 package&lt;/a&gt;.&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;/etc/krb5.conf&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;

&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Windows AD (Kerberos) authentication is only available for self-managed Grafana installations. It is not supported in Grafana Cloud. For Grafana Cloud deployments connecting to SQL Server, use SQL Server Authentication or Azure Entra ID.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Kerberos SPN requirements:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;For Kerberos authentication to succeed, a Service Principal Name (SPN) must be registered for the SQL Server instance that matches the hostname Grafana uses to connect. This is especially important when connecting through Availability Group Listeners or DNS aliases.&lt;/p&gt;
&lt;p&gt;Register SPNs using the &lt;code&gt;setspn&lt;/code&gt; command on the SQL Server host:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;text&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-text&#34;&gt;setspn -S MSSQLSvc/&amp;lt;SQL_SERVER_FQDN&amp;gt;:1433 &amp;lt;DOMAIN&amp;gt;\&amp;lt;SERVICE_ACCOUNT&amp;gt;
setspn -S MSSQLSvc/&amp;lt;SQL_SERVER_FQDN&amp;gt; &amp;lt;DOMAIN&amp;gt;\&amp;lt;SERVICE_ACCOUNT&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If Grafana connects through a Listener or alias, register an additional SPN for that name. Verify registered SPNs with &lt;code&gt;setspn -L &amp;lt;DOMAIN&amp;gt;\&amp;lt;SERVICE_ACCOUNT&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;!-- vale Grafana.Spelling = YES --&gt;
&lt;h3 id=&#34;connect-to-on-premises-sql-server-from-grafana-cloud&#34;&gt;Connect to on-premises SQL Server from Grafana Cloud&lt;/h3&gt;
&lt;p&gt;If your SQL Server instance is in a private network (on-premises, VPN, or VPC), Grafana Cloud cannot reach it directly over the internet. You must use &lt;strong&gt;Private data source connect (PDC)&lt;/strong&gt; to establish a secure tunnel between your Grafana Cloud stack and your private network.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;PDC is required for any SQL Server that isn&amp;rsquo;t publicly accessible from the internet. Firewall allowlisting alone is not sufficient because Grafana Cloud doesn&amp;rsquo;t use static IP addresses for data source connections.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Network prerequisites:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Port 22 (SSH):&lt;/strong&gt; The PDC agent on your network must be able to reach the Grafana Cloud PDC endpoint over port 22 for the SSH tunnel.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Port 1433 (SQL Server):&lt;/strong&gt; The PDC agent must be able to reach your SQL Server instance on port 1433 (or your custom SQL Server port).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DNS resolution:&lt;/strong&gt; The PDC agent must be able to resolve the SQL Server hostname from within your private network.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Set up PDC for Microsoft SQL Server:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In your Grafana Cloud stack, navigate to &lt;strong&gt;Connections&lt;/strong&gt; &amp;gt; &lt;strong&gt;Private data source connect&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Create a new PDC connection or use an existing one.&lt;/li&gt;
&lt;li&gt;Install and configure the PDC agent on a host within your private network that has access to the SQL Server instance. For detailed instructions, refer to &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/configure-pdc/#configure-grafana-private-data-source-connect-pdc&#34;&gt;Configure Grafana private data source connect (PDC)&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Return to the Microsoft SQL Server data source configuration.&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;Private data source connect&lt;/strong&gt;, select your PDC connection from the drop-down.&lt;/li&gt;
&lt;li&gt;Enter the SQL Server hostname as it&amp;rsquo;s resolvable from within your private network (not a public DNS name).&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save &amp;amp; test&lt;/strong&gt; to verify connectivity.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Click &lt;strong&gt;Manage private data source connect&lt;/strong&gt; to open your PDC connection page and view your configuration details.&lt;/p&gt;
&lt;p&gt;For more information about PDC, refer to &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;Private data source connect (PDC)&lt;/a&gt;.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;If you previously connected using a self-managed Grafana instance and are migrating to Grafana Cloud, you must configure PDC before your private SQL Server is accessible. Direct network access methods that worked with self-managed Grafana (VPN peering, private endpoints) don&amp;rsquo;t apply to Grafana Cloud.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;After configuring your MSSQL data source options, click &lt;strong&gt;Save &amp;amp; test&lt;/strong&gt; at the bottom to test the connection. You should see a confirmation dialog box that says:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Database Connection OK&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&#34;azure-entra-id-formerly-azure-ad-authentication&#34;&gt;Azure Entra ID (formerly Azure AD) Authentication&lt;/h3&gt;
&lt;p&gt;The following Azure authentication methods are supported:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;App Registration (service principal)&lt;/li&gt;
&lt;li&gt;Managed Identity&lt;/li&gt;
&lt;li&gt;Current User authentication&lt;/li&gt;
&lt;li&gt;Azure Entra Password&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The Azure SQL Server that you are connecting to must support Azure Entra authentication. For configuration details, refer to the &lt;a href=&#34;https://learn.microsoft.com/en-us/azure/azure-sql/database/authentication-aad-configure?view=azuresql&amp;amp;tabs=azure-portal&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Azure SQL documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&#34;required-server-configuration&#34;&gt;Required server configuration&lt;/h4&gt;
&lt;p&gt;Before you can use any Azure Entra ID authentication method, you must enable Azure authentication in the Grafana server configuration. Add the following to your &lt;code&gt;grafana.ini&lt;/code&gt; or &lt;code&gt;custom.ini&lt;/code&gt; file:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;ini&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-ini&#34;&gt;[azure]
azure_auth_enabled = true&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Depending on the method you choose, additional flags are required (documented in each section below). After changing the &lt;code&gt;.ini&lt;/code&gt; file, restart the Grafana server for the changes to take effect.&lt;/p&gt;
&lt;h4 id=&#34;current-user-authentication&#34;&gt;Current User authentication&lt;/h4&gt;
&lt;p&gt;This is the recommended authentication mechanism when working with SQL Server instances that are hosted in Azure. It allows users to be authenticated to and query the database using their own credentials rather than long-lived credentials.&lt;/p&gt;
&lt;p&gt;This authentication method requires your Grafana instance to be configured with Azure Entra ID (formerly Active Directory) authentication for login. With Azure Entra ID login, this method can be used to forward the currently logged in user’s credentials to the data source. The users credentials will then be used when requesting data from the data source. For details on how to configure your Grafana instance using Azure Entra refer to the 
    &lt;a href=&#34;/docs/grafana/v13.2/setup-grafana/configure-access/configure-authentication/azuread/&#34;&gt;documentation&lt;/a&gt;.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Additional configuration is required to ensure that the App Registration used to login a user via Azure provides an access token with the permissions required by the data source.&lt;/p&gt;
&lt;p&gt;The App Registration must be configured to issue both &lt;strong&gt;Access Tokens&lt;/strong&gt; and &lt;strong&gt;ID Tokens&lt;/strong&gt;.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In the Azure Portal, open the App Registration that requires configuration.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Authentication&lt;/strong&gt; in the side menu.&lt;/li&gt;
&lt;li&gt;Under &lt;strong&gt;Implicit grant and hybrid flows&lt;/strong&gt; check both the &lt;strong&gt;Access tokens&lt;/strong&gt; and &lt;strong&gt;ID tokens&lt;/strong&gt; boxes.&lt;/li&gt;
&lt;li&gt;Save the changes to ensure the App Registration is updated.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The App Registration must also be configured with additional &lt;strong&gt;API Permissions&lt;/strong&gt; to provide authenticated users with access to the APIs utilised by the data source.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In the Azure Portal, open the App Registration that requires configuration.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;API Permissions&lt;/strong&gt; in the side menu.&lt;/li&gt;
&lt;li&gt;Ensure the &lt;code&gt;openid&lt;/code&gt;, &lt;code&gt;profile&lt;/code&gt;, &lt;code&gt;email&lt;/code&gt;, and &lt;code&gt;offline_access&lt;/code&gt; permissions are present under the &lt;strong&gt;Microsoft Graph&lt;/strong&gt; section. If not, they must be added.&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Add a permission&lt;/strong&gt; and choose the following permissions. They must be added individually. Refer to the &lt;a href=&#34;https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-configure-app-access-web-apis&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Azure documentation&lt;/a&gt; for more information.
&lt;ul&gt;
&lt;li&gt;Select &lt;strong&gt;APIs my organization uses&lt;/strong&gt; &amp;gt; Search for &lt;strong&gt;Azure SQL&lt;/strong&gt; and select it &amp;gt; &lt;strong&gt;Delegated permissions&lt;/strong&gt; &amp;gt; &lt;code&gt;user_impersonation&lt;/code&gt; &amp;gt; &lt;strong&gt;Add permissions&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;After all permissions have been added, the Azure authentication section in Grafana must be updated. The &lt;code&gt;scopes&lt;/code&gt; section must be updated to include the &lt;code&gt;.default&lt;/code&gt; scope to ensure that a token with access to all APIs declared on the App Registration is requested by Grafana. After updated the scopes value should equal: &lt;code&gt;.default openid email profile&lt;/code&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;This method of authentication doesn&amp;rsquo;t inherently support all backend functionality as a user&amp;rsquo;s credentials won&amp;rsquo;t be in scope. Affected functionality includes alerting, reporting, and recorded queries. Also, note that query and resource caching is disabled by default for data sources using current user authentication.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To enable current user authentication for Grafana:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Set the &lt;code&gt;user_identity_enabled&lt;/code&gt; flag in the &lt;code&gt;[azure]&lt;/code&gt; section of the 
    &lt;a href=&#34;/docs/grafana/v13.2/setup-grafana/configure-grafana/#azure&#34;&gt;Grafana server configuration&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;ini&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-ini&#34;&gt;[azure]
user_identity_enabled = true&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the SQL Server data source configuration, set &lt;strong&gt;Authentication&lt;/strong&gt; to &lt;strong&gt;Azure AD Authentication&lt;/strong&gt; and the Azure Authentication type to &lt;strong&gt;Current User&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;app-registration&#34;&gt;App Registration&lt;/h4&gt;
&lt;p&gt;Use an app registration (service principal) to authenticate the data source with a client ID and secret. This is the recommended method for automated, non-interactive access to Azure SQL.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;An app registration created in Azure Entra. For instructions, refer to the &lt;a href=&#34;https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal#get-tenant-and-app-id-values-for-signing-in&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Azure documentation for service principals&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The tenant ID, client (application) ID, and a client secret from the app registration.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Step 1: Add the app registration as a database user&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Connect to your Azure SQL database as a user with administrative permissions (the user must have the ability to read your Azure Entra directory, for example, by possessing the &lt;code&gt;Directory Readers&lt;/code&gt; role).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run the following SQL to create a user for the app registration:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;CREATE USER [&amp;lt;APP_REGISTRATION_NAME&amp;gt;] FROM EXTERNAL PROVIDER;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Grant the created user appropriate permissions. Grafana recommends read-only access:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;ALTER ROLE db_datareader ADD MEMBER [&amp;lt;APP_REGISTRATION_NAME&amp;gt;];&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;Step 2: Configure the Grafana server&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Ensure &lt;code&gt;azure_auth_enabled&lt;/code&gt; is set in your &lt;code&gt;grafana.ini&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;ini&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-ini&#34;&gt;[azure]
azure_auth_enabled = true&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Step 3: Configure the data source&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In the SQL Server data source configuration, set &lt;strong&gt;Authentication&lt;/strong&gt; to &lt;strong&gt;Azure AD Authentication&lt;/strong&gt; and the Azure Authentication type to &lt;strong&gt;App Registration&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Set &lt;strong&gt;Azure Cloud&lt;/strong&gt; to &lt;strong&gt;Azure&lt;/strong&gt; (for the Azure public cloud).&lt;/li&gt;
&lt;li&gt;Enter the &lt;strong&gt;Directory (tenant) ID&lt;/strong&gt;, &lt;strong&gt;Application (client) ID&lt;/strong&gt;, and &lt;strong&gt;Client Secret&lt;/strong&gt; from your app registration.&lt;/li&gt;
&lt;/ol&gt;
&lt;h4 id=&#34;managed-identity&#34;&gt;Managed Identity&lt;/h4&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Managed Identity is available only in &lt;a href=&#34;https://azure.microsoft.com/en-us/products/managed-grafana&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Azure Managed Grafana&lt;/a&gt; or self-managed Grafana deployed in Azure. It is not available in Grafana Cloud.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;You can use managed identity to configure SQL Server in Grafana if you host Grafana in Azure (such as an App Service or with Azure Virtual Machines) and have managed identity enabled on your VM.
This lets you securely authenticate data sources without manually configuring credentials.
For details on Azure managed identities, refer to the &lt;a href=&#34;https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Azure documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To enable managed identity for Grafana:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Set both &lt;code&gt;azure_auth_enabled&lt;/code&gt; and &lt;code&gt;managed_identity_enabled&lt;/code&gt; in the &lt;code&gt;[azure]&lt;/code&gt; section of the 
    &lt;a href=&#34;/docs/grafana/v13.2/setup-grafana/configure-grafana/#azure&#34;&gt;Grafana server configuration&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;ini&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-ini&#34;&gt;[azure]
azure_auth_enabled = true
managed_identity_enabled = true&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the SQL Server data source configuration, set &lt;strong&gt;Authentication&lt;/strong&gt; to &lt;strong&gt;Azure AD Authentication&lt;/strong&gt; and the Azure Authentication type to &lt;strong&gt;Managed Identity&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This hides the directory ID, application ID, and client secret fields, and the data source uses managed identity to authenticate to SQL Server.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Optionally, set &lt;code&gt;managed_identity_client_id&lt;/code&gt; in the &lt;code&gt;[azure]&lt;/code&gt; section to use a user-assigned managed identity instead of the default system-assigned identity.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Ensure that the managed identity is added to your Azure SQL instance as a user.&lt;/p&gt;
&lt;h3 id=&#34;azure-entra-password&#34;&gt;Azure Entra Password&lt;/h3&gt;


&lt;div class=&#34;admonition admonition-warning&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Warning&lt;/p&gt;&lt;p&gt;Azure Entra Password is not a recommended authentication mechanism as it requires configuration using a single users password. Consider an alternative authentication method such as current user authentication or app registration.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;You can connect to an Azure SQL database using the username and password of a user that has permissions in the desired database. This also requires an app registration to be configured with access to the database.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;To enable Azure Entra password for Grafana:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Set the &lt;code&gt;azure_entra_password_credentials_enabled&lt;/code&gt; flag in the &lt;code&gt;[azure]&lt;/code&gt; section of the 
    &lt;a href=&#34;/docs/grafana/v13.2/setup-grafana/configure-grafana/#azure&#34;&gt;Grafana server configuration&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;ini&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-ini&#34;&gt;[azure]
azure_entra_password_credentials_enabled = true&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the SQL Server data source configuration, set &lt;strong&gt;Authentication&lt;/strong&gt; to &lt;strong&gt;Azure AD Authentication&lt;/strong&gt; and the Azure Authentication type to &lt;strong&gt;Azure Entra Password&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set the &lt;strong&gt;User ID&lt;/strong&gt; value to the username of the user in the Azure SQL database.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set the &lt;strong&gt;Application Client ID&lt;/strong&gt; to the client ID of the app registration that has been added to the Azure SQL database&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Set the &lt;strong&gt;Password&lt;/strong&gt; value to the password of the user in the Azure SQL database.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;min-time-interval&#34;&gt;Min time interval&lt;/h3&gt;
&lt;p&gt;The &lt;strong&gt;Min time interval&lt;/strong&gt; setting defines a lower limit for the 
    &lt;a href=&#34;/docs/grafana/v13.2/dashboards/variables/add-template-variables/#__interval&#34;&gt;&lt;code&gt;$__interval&lt;/code&gt;&lt;/a&gt; and [&lt;code&gt;$__interval_ms&lt;/code&gt;][add-template-variables-interval_ms] variables.&lt;/p&gt;
&lt;p&gt;This value &lt;em&gt;must&lt;/em&gt; be formatted as a number followed by a valid time identifier:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Identifier&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;y&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;year&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;M&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;month&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;w&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;week&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;d&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;day&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;h&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;hour&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;m&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;minute&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;s&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;second&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;ms&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;millisecond&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;Grafana recommends setting this value to match your Microsoft SQL Server write frequency.
For example, use &lt;code&gt;1m&lt;/code&gt; if Microsoft SQL Server writes data every minute.&lt;/p&gt;
&lt;p&gt;You can also override this setting in a dashboard panel under its data source options.&lt;/p&gt;
&lt;h3 id=&#34;database-user-permissions&#34;&gt;Database user permissions&lt;/h3&gt;
&lt;p&gt;When adding a data source, ensure the database user you specify has only SELECT permissions on the relevant database and tables. Grafana does not validate the safety of queries, which means they can include potentially harmful SQL statements, such as &lt;code&gt;USE otherdb&lt;/code&gt;; or &lt;code&gt;DROP TABLE user;&lt;/code&gt;, which could get executed. To minimize this risk, Grafana strongly recommends creating a dedicated MSSQL user with restricted permissions.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;CREATE USER grafanareader WITH PASSWORD &amp;#39;password&amp;#39;
GRANT SELECT ON dbo.YourTable3 TO grafanareader&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Also, ensure that the user doesn&amp;rsquo;t have any unwanted privileges from the public role.&lt;/p&gt;
&lt;h3 id=&#34;diagnose-connection-issues&#34;&gt;Diagnose connection issues&lt;/h3&gt;
&lt;p&gt;If you use older versions of Microsoft SQL Server, such as 2008 and 2008R2, you might need to disable encryption before you can connect the data source.&lt;/p&gt;
&lt;p&gt;Grafana recommends that you use the latest available service pack for optimal compatibility.&lt;/p&gt;
&lt;h3 id=&#34;provision-the-data-source&#34;&gt;Provision the data source&lt;/h3&gt;
&lt;p&gt;You can define and configure the data source in YAML files as part of the Grafana provisioning system. For more information about provisioning, and for available configuration options, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/administration/provisioning/&#34;&gt;Provision Grafana&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&#34;provisioning-example&#34;&gt;Provisioning example&lt;/h4&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;YAML&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-yaml&#34;&gt;apiVersion: 1

datasources:
  - name: MSSQL
    type: mssql
    url: localhost:1433
    user: grafana
    jsonData:
      database: grafana
      maxOpenConns: 100
      maxIdleConns: 100
      maxIdleConnsAuto: true
      connMaxLifetime: 14400
      connectionTimeout: 0
      encrypt: &amp;#39;false&amp;#39;
    secureJsonData:
      password: &amp;#39;Password!&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;configure-with-terraform&#34;&gt;Configure with Terraform&lt;/h3&gt;
&lt;p&gt;You can configure the Microsoft SQL Server data source using &lt;a href=&#34;https://www.terraform.io/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Terraform&lt;/a&gt; with the &lt;a href=&#34;https://registry.terraform.io/providers/grafana/grafana/latest/docs&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana Terraform provider&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For more information about provisioning resources with Terraform, refer to the &lt;a href=&#34;/docs/grafana-cloud/developer-resources/infrastructure-as-code/terraform/&#34;&gt;Grafana as code using Terraform&lt;/a&gt; documentation.&lt;/p&gt;
&lt;h4 id=&#34;terraform-example&#34;&gt;Terraform example&lt;/h4&gt;
&lt;p&gt;The following example creates a basic Microsoft SQL Server data source:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;hcl&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-hcl&#34;&gt;resource &amp;#34;grafana_data_source&amp;#34; &amp;#34;mssql&amp;#34; {
  name = &amp;#34;MSSQL&amp;#34;
  type = &amp;#34;mssql&amp;#34;
  url  = &amp;#34;localhost:1433&amp;#34;
  user = &amp;#34;grafana&amp;#34;

  json_data_encoded = jsonencode({
    database           = &amp;#34;grafana&amp;#34;
    maxOpenConns       = 100
    maxIdleConns       = 100
    maxIdleConnsAuto   = true
    connMaxLifetime    = 14400
    connectionTimeout  = 0
    encrypt            = &amp;#34;false&amp;#34;
  })

  secure_json_data_encoded = jsonencode({
    password = &amp;#34;Password!&amp;#34;
  })
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;For all available configuration options, refer to the &lt;a href=&#34;https://registry.terraform.io/providers/grafana/grafana/latest/docs/resources/data_source&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana provider data source resource documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;next-steps&#34;&gt;Next steps&lt;/h2&gt;
&lt;p&gt;After configuring your Microsoft SQL Server data source, you can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/query-editor/&#34;&gt;Write queries&lt;/a&gt; using the query editor to explore and visualize your data&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/template-variables/&#34;&gt;Create template variables&lt;/a&gt; to build dynamic, reusable dashboards&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/annotations/&#34;&gt;Add annotations&lt;/a&gt; to overlay SQL Server events on your graphs&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/alerting/&#34;&gt;Set up alerting&lt;/a&gt; to create alert rules based on your SQL Server data&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/troubleshooting/&#34;&gt;Troubleshoot issues&lt;/a&gt; if you encounter problems with your data source&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="configure-the-microsoft-sql-server-data-source">Configure the Microsoft SQL Server data source&lt;/h1>
&lt;p>This document provides instructions for configuring the Microsoft SQL Server data source and explains available configuration options. For general information on adding and managing data sources, refer to
&lt;a href="/docs/grafana/v13.2/datasources/">Grafana data sources&lt;/a> and
&lt;a href="/docs/grafana/v13.2/administration/data-source-management/">Data source management&lt;/a>.&lt;/p></description></item><item><title>Microsoft SQL Server query editor</title><link>https://grafana.com/docs/grafana/v13.2/datasources/mssql/query-editor/</link><pubDate>Tue, 18 Aug 2026 10:15:08 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.2/datasources/mssql/query-editor/</guid><content><![CDATA[&lt;h1 id=&#34;microsoft-sql-server-query-editor&#34;&gt;Microsoft SQL Server query editor&lt;/h1&gt;
&lt;p&gt;The MSSQL query editor lets you write Transact-SQL queries directly in Grafana, with built-in macros and formatting options designed for time series and table visualizations. You can open it from 
    &lt;a href=&#34;/docs/grafana/v13.2/explore/&#34;&gt;Explore&lt;/a&gt; or from any dashboard panel in edit mode.&lt;/p&gt;
&lt;p&gt;This page covers MSSQL-specific query features. For general querying concepts shared across all data sources, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/panels-visualizations/query-transform-data/&#34;&gt;Query and transform data&lt;/a&gt;. For Transact-SQL syntax, refer to &lt;a href=&#34;https://learn.microsoft.com/en-us/sql/t-sql/tutorial-writing-transact-sql-statements?view=sql-server-ver17&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Write Transact-SQL statements&lt;/a&gt; and &lt;a href=&#34;https://learn.microsoft.com/en-us/sql/t-sql/language-reference?view=sql-server-ver17&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Transact-SQL reference&lt;/a&gt; in the Microsoft documentation.&lt;/p&gt;
&lt;p&gt;The Microsoft SQL Server query editor has two modes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#builder-mode&#34;&gt;Builder mode&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#code-mode&#34;&gt;Code mode&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To switch between the editor modes, select the corresponding &lt;strong&gt;Builder&lt;/strong&gt; and &lt;strong&gt;Code&lt;/strong&gt; tabs in the upper right.&lt;/p&gt;
&lt;p&gt;&lt;img
  class=&#34;lazyload d-inline-block&#34;
  data-src=&#34;/media/mssql/mssql-query-editor-v12.png&#34;
  alt=&#34;MSSQL query builder&#34; width=&#34;1243&#34;
     height=&#34;286&#34;/&gt;&lt;/p&gt;


&lt;div class=&#34;admonition admonition-warning&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Warning&lt;/p&gt;&lt;p&gt;When switching from &lt;strong&gt;Code&lt;/strong&gt; mode to &lt;strong&gt;Builder&lt;/strong&gt; mode, any changes made to your SQL query aren&amp;rsquo;t saved and aren&amp;rsquo;t shown in the builder interface. You can choose to copy your code to the clipboard or discard the changes.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;To run a query, select &lt;strong&gt;Run query&lt;/strong&gt; in the upper right of the editor.&lt;/p&gt;
&lt;p&gt;In addition to writing queries, the query editor also allows you to create and use:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;#macros&#34;&gt;Macros&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;#use-stored-procedures&#34;&gt;Stored procedures&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;builder-mode&#34;&gt;Builder mode&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Builder mode&lt;/strong&gt; allows you to build queries using a visual interface. This mode is great for users who prefer a guided query experience or are just getting started with SQL.&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 1098px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/media/docs/mssql/mssql-builder-mode-v12.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/media/docs/mssql/mssql-builder-mode-v12.png&#34;data-srcset=&#34;/media/docs/mssql/mssql-builder-mode-v12.png?w=320 320w, /media/docs/mssql/mssql-builder-mode-v12.png?w=550 550w, /media/docs/mssql/mssql-builder-mode-v12.png?w=750 750w, /media/docs/mssql/mssql-builder-mode-v12.png?w=900 900w, /media/docs/mssql/mssql-builder-mode-v12.png?w=1040 1040w, /media/docs/mssql/mssql-builder-mode-v12.png?w=1240 1240w, /media/docs/mssql/mssql-builder-mode-v12.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;MSSQL builder mode&amp;gt;&#34;width=&#34;1098&#34;height=&#34;567&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/media/docs/mssql/mssql-builder-mode-v12.png&#34;
            alt=&#34;MSSQL builder mode&amp;gt;&#34;width=&#34;1098&#34;height=&#34;567&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;The following components help you build a T-SQL query:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Format&lt;/strong&gt; - Select a format response from the drop-down for the MSSQL query. The default is &lt;strong&gt;Table&lt;/strong&gt;. Refer to &lt;a href=&#34;#table-queries&#34;&gt;Table queries&lt;/a&gt; and &lt;a href=&#34;#time-series-queries&#34;&gt;Time series queries&lt;/a&gt; for more information and examples. If you select the &lt;strong&gt;Time series&lt;/strong&gt; format option, you must include a &lt;code&gt;time&lt;/code&gt; column.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Dataset&lt;/strong&gt; - Select a database to query from the drop-down. Grafana automatically populates the drop-down with all databases the user has access to. If a database is set in the &lt;strong&gt;Database&lt;/strong&gt; field on the data source configuration page or via a provisioning file, users are limited to querying only that database.&lt;/p&gt;
&lt;p&gt;Note that &lt;code&gt;tempdb&lt;/code&gt;, &lt;code&gt;model&lt;/code&gt;, &lt;code&gt;msdb&lt;/code&gt;, and &lt;code&gt;master&lt;/code&gt; system databases are not included in the query editor drop-down.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Table&lt;/strong&gt; - Select a table from the drop-down. After selecting a database, the next drop-down displays all available tables in that database.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Data operations&lt;/strong&gt; - &lt;em&gt;Optional&lt;/em&gt;. Select an aggregation or a macro from the drop-down. You can add multiple data operations by clicking the &lt;strong&gt;&#43; sign&lt;/strong&gt;. Click the &lt;strong&gt;garbage can icon&lt;/strong&gt; to remove data operations.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Column&lt;/strong&gt; - Select a column on which to run the aggregation.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Interval&lt;/strong&gt; - Select an interval from the drop-down. You&amp;rsquo;ll see this option when you choose a &lt;code&gt;time group&lt;/code&gt; macro from the drop-down.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Fill&lt;/strong&gt; - &lt;em&gt;Optional&lt;/em&gt;. Add a &lt;code&gt;FILL&lt;/code&gt; method to populate missing time intervals with default values (such as NULL, 0, or a specified value) when no data exists for those intervals. This ensures continuity in the time series, avoiding gaps in visualizations.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Alias&lt;/strong&gt; - &lt;em&gt;Optional&lt;/em&gt;. Add an alias from the drop-down. You can also add your own alias by typing it in the box and clicking &lt;strong&gt;Enter&lt;/strong&gt;. Remove an alias by clicking the &lt;strong&gt;X&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Filter&lt;/strong&gt; - Toggle to add filters.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Filter by column value&lt;/strong&gt; - &lt;em&gt;Optional&lt;/em&gt;. If you toggle &lt;strong&gt;Filter&lt;/strong&gt; you can add a column to filter by from the drop-down. To filter by additional columns, click the &lt;strong&gt;&#43; sign&lt;/strong&gt; to the right of the condition drop-down. You can choose a variety of operators from the drop-down next to the condition. When multiple filters are added, use the &lt;code&gt;AND&lt;/code&gt; or &lt;code&gt;OR&lt;/code&gt; operators to define how conditions are evaluated. &lt;code&gt;AND&lt;/code&gt; requires all conditions to be true, while &lt;code&gt;OR&lt;/code&gt; requires any condition to be true. Use the second drop-down to select the filter value. To remove a filter, click the &lt;strong&gt;X icon&lt;/strong&gt; next to it. If you select a &lt;code&gt;date-type&lt;/code&gt; column, you can use macros from the operator list and choose &lt;code&gt;timeFilter&lt;/code&gt; to insert the &lt;code&gt;$\_\_timeFilter&lt;/code&gt; macro into your query with the selected date column.&lt;/p&gt;
&lt;p&gt;After selecting a date type column, you can choose Macros from the operators list and select &lt;code&gt;timeFilter&lt;/code&gt;, which adds the &lt;code&gt;$\_\_timeFilter&lt;/code&gt; macro to the query with the selected date column. Refer to &lt;a href=&#34;#macros&#34;&gt;Macros&lt;/a&gt; for more information.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Group&lt;/strong&gt; - Toggle to add a &lt;code&gt;GROUP BY&lt;/code&gt; column.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Group by column&lt;/strong&gt; - Select a column to filter by from the drop-down. Click the &lt;strong&gt;&#43;sign&lt;/strong&gt; to filter by multiple columns. Click the &lt;strong&gt;X&lt;/strong&gt; to remove a filter.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Order&lt;/strong&gt; - Toggle to add an &lt;code&gt;ORDER BY&lt;/code&gt; statement.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Order by&lt;/strong&gt; - Select a column to order by from the drop-down. Select ascending (&lt;code&gt;ASC&lt;/code&gt;) or descending (&lt;code&gt;DESC&lt;/code&gt;) order.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Limit&lt;/strong&gt; - You can add an optional limit on the number of retrieved results. Default is 50.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Preview&lt;/strong&gt; - Toggle for a preview of the SQL query generated by the query builder. Preview is toggled on by default.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For additional detail about using formats, refer to &lt;a href=&#34;#table-queries&#34;&gt;Table queries&lt;/a&gt; and &lt;a href=&#34;#time-series-queries&#34;&gt;Time series queries&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;code-mode&#34;&gt;Code mode&lt;/h2&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 963px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/static/img/docs/v92/sql_code_editor.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/static/img/docs/v92/sql_code_editor.png&#34;data-srcset=&#34;/static/img/docs/v92/sql_code_editor.png?w=320 320w, /static/img/docs/v92/sql_code_editor.png?w=550 550w, /static/img/docs/v92/sql_code_editor.png?w=750 750w, /static/img/docs/v92/sql_code_editor.png?w=900 900w, /static/img/docs/v92/sql_code_editor.png?w=1040 1040w, /static/img/docs/v92/sql_code_editor.png?w=1240 1240w, /static/img/docs/v92/sql_code_editor.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;&#34;width=&#34;963&#34;height=&#34;326&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/v92/sql_code_editor.png&#34;
            alt=&#34;&#34;width=&#34;963&#34;height=&#34;326&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;&lt;strong&gt;Code mode&lt;/strong&gt; lets you build complex queries using a text editor with helpful features like autocompletion and syntax highlighting.&lt;/p&gt;
&lt;p&gt;This mode is ideal for advanced users who need full control over the SQL query or want to use features not available in visual query mode. It&amp;rsquo;s especially useful for writing subqueries, using macros, or applying advanced filtering and formatting. You can switch back to visual mode, but note that some custom queries may not be fully compatible.&lt;/p&gt;
&lt;h3 id=&#34;code-mode-toolbar-features&#34;&gt;Code mode toolbar features&lt;/h3&gt;
&lt;p&gt;Code mode has several features in a toolbar located in the editor&amp;rsquo;s lower-right corner.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;To reformat the query, click the brackets button (&lt;code&gt;{}&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;To expand the code editor, click the chevron button pointing downward.&lt;/li&gt;
&lt;li&gt;To run the query, click the &lt;strong&gt;Run query&lt;/strong&gt; button or use the keyboard shortcut &lt;strong&gt;&lt;key&gt;Ctrl&lt;/key&gt;/&lt;key&gt;Cmd&lt;/key&gt; &#43; &lt;key&gt;Enter&lt;/key&gt;/&lt;key&gt;Return&lt;/key&gt;&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;use-autocompletion&#34;&gt;Use autocompletion&lt;/h3&gt;
&lt;p&gt;Code mode&amp;rsquo;s autocompletion feature works automatically while typing.
To manually trigger autocompletion, use the keyboard shortcut &lt;key&gt;Ctrl&lt;/key&gt;/&lt;key&gt;Cmd&lt;/key&gt; &#43; &lt;key&gt;Space&lt;/key&gt;.&lt;/p&gt;
&lt;p&gt;Code mode supports autocompletion of tables, columns, SQL keywords, standard SQL functions, Grafana template variables, and Grafana macros.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;You can&amp;rsquo;t autocomplete columns until you&amp;rsquo;ve specified a table.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;macros&#34;&gt;Macros&lt;/h2&gt;
&lt;p&gt;To simplify syntax and to allow for dynamic components, such as date range filters, you can add macros to your query.&lt;/p&gt;
&lt;p&gt;Use macros in the &lt;code&gt;SELECT&lt;/code&gt; clause to simplify the creation of time series queries.
From the &lt;strong&gt;Data operations&lt;/strong&gt; drop-down, choose a macro such as &lt;code&gt;$\_\_timeGroup&lt;/code&gt; or &lt;code&gt;$\_\_timeGroupAlias&lt;/code&gt;. Then, select a time column from the &lt;strong&gt;Column&lt;/strong&gt; drop-down and a time interval from the &lt;strong&gt;Interval&lt;/strong&gt; drop-down. This generates a time-series query based on your selected time grouping.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-warning&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Warning&lt;/p&gt;&lt;p&gt;Time macros (&lt;code&gt;$__time&lt;/code&gt;, &lt;code&gt;$__timeFilter&lt;/code&gt;, etc.) don&amp;rsquo;t support time zone parameters in Microsoft SQL Server and always expand to UTC values. If your timestamps aren&amp;rsquo;t stored in UTC (common with &lt;code&gt;datetime&lt;/code&gt;/&lt;code&gt;datetime2&lt;/code&gt; types), convert them to UTC in your SQL query using &lt;code&gt;AT TIME ZONE … AT TIME ZONE &#39;UTC&#39;&lt;/code&gt; rather than passing a time zone argument to a macro.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;&lt;strong&gt;Macro&lt;/strong&gt;&lt;/th&gt;
              &lt;th&gt;&lt;strong&gt;Description&lt;/strong&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__time(dateColumn)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Renames the specified column to &lt;code&gt;_time&lt;/code&gt;. Example: &lt;code&gt;dateColumn AS time&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeEpoch(dateColumn)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Converts a &lt;code&gt;DATETIME&lt;/code&gt; column to a Unix timestamp and renames it to &lt;code&gt;_time&lt;/code&gt;. Example: &lt;code&gt;DATEDIFF(second, &#39;1970-01-01&#39;, dateColumn) AS time&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeFilter(dateColumn)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Adds a time range filter for the specified column. Example: &lt;code&gt;dateColumn BETWEEN &#39;2017-04-21T05:01:17Z&#39; AND &#39;2017-04-21T05:06:17Z&#39;&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeFrom()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Returns the start of the current time range. Example: &lt;code&gt;&#39;2017-04-21T05:01:17Z&#39;&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeTo()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Returns the end of the current time range. Example: &lt;code&gt;&#39;2017-04-21T05:06:17Z&#39;&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeGroup(dateColumn, &#39;5m&#39;[, fillValue])&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Groups the specified time column into intervals (for example, 5 minutes). Optionally fills gaps with a value like &lt;code&gt;0&lt;/code&gt;, &lt;code&gt;NULL&lt;/code&gt;, or &lt;code&gt;previous&lt;/code&gt;. Example: &lt;code&gt;CAST(ROUND(DATEDIFF(second, &#39;1970-01-01&#39;, time_column)/300.0, 0) AS bigint) * 300&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeGroup(dateColumn, &#39;5m&#39;, 0)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as above, with &lt;code&gt;0&lt;/code&gt; used to fill missing data points.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeGroup(dateColumn, &#39;5m&#39;, NULL)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as above, with &lt;code&gt;NULL&lt;/code&gt; used for missing data points.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeGroup(dateColumn, &#39;5m&#39;, previous)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as above, using the previous value to fill gaps. If no previous value exists, &lt;code&gt;NULL&lt;/code&gt; is used.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeGroupAlias(dateColumn, &#39;5m&#39;)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as &lt;code&gt;$__timeGroup&lt;/code&gt;, but also adds an alias to the resulting column.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochFilter(dateColumn)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Adds a time range filter using Unix timestamps. Example: &lt;code&gt;dateColumn &amp;gt; 1494410783 AND dateColumn &amp;lt; 1494497183&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochFrom()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Returns the start of the current time range as a Unix timestamp. Example: &lt;code&gt;1494410783&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochTo()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Returns the end of the current time range as a Unix timestamp. Example: &lt;code&gt;1494497183&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochNanoFilter(dateColumn)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Adds a time range filter using nanosecond-precision Unix timestamps. Example: &lt;code&gt;dateColumn &amp;gt; 1494410783152415214 AND dateColumn &amp;lt; 1494497183142514872&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochNanoFrom()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Returns the start of the current time range as a nanosecond Unix timestamp. Example: &lt;code&gt;1494410783152415214&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochNanoTo()&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Returns the end of the current time range as a nanosecond Unix timestamp. Example: &lt;code&gt;1494497183142514872&lt;/code&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochGroup(dateColumn, &#39;5m&#39;, [fillMode])&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as &lt;code&gt;$__timeGroup&lt;/code&gt;, but for Unix timestamps. Optional &lt;code&gt;fillMode&lt;/code&gt; controls how to handle missing points.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochGroupAlias(dateColumn, &#39;5m&#39;, [fillMode])&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Same as above, but adds an alias to the grouped column.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;view-the-interpolated-query&#34;&gt;View the interpolated query&lt;/h3&gt;
&lt;p&gt;The query editor includes a &lt;strong&gt;Generated SQL&lt;/strong&gt; link that appears after you run a query while editing a panel. Click this link to view the raw interpolated SQL that Grafana executed, including any macros that were expanded during query processing.&lt;/p&gt;
&lt;h2 id=&#34;table-queries&#34;&gt;Table queries&lt;/h2&gt;
&lt;p&gt;To create a Table query, set the &lt;strong&gt;Format&lt;/strong&gt; option in the query editor to 
    &lt;a href=&#34;/docs/grafana/v13.2/panels-visualizations/visualizations/table/&#34;&gt;&lt;strong&gt;Table&lt;/strong&gt;&lt;/a&gt;. This allows you to write any valid SQL query, and the Table panel displays the results using the returned columns and rows.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;CREATE TABLE [event] (
  time_sec bigint,
  description nvarchar(100),
  tags nvarchar(100),
)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;CREATE TABLE [mssql_types] (
  c_bit bit, c_tinyint tinyint, c_smallint smallint, c_int int, c_bigint bigint, c_money money, c_smallmoney smallmoney, c_numeric numeric(10,5),
  c_real real, c_decimal decimal(10,2), c_float float,
  c_char char(10), c_varchar varchar(10), c_text text,
  c_nchar nchar(12), c_nvarchar nvarchar(12), c_ntext ntext,
  c_datetime datetime,  c_datetime2 datetime2, c_smalldatetime smalldatetime, c_date date, c_time time, c_datetimeoffset datetimeoffset
)

INSERT INTO [mssql_types]
SELECT
  1, 5, 20020, 980300, 1420070400, &amp;#39;$20000.15&amp;#39;, &amp;#39;£2.15&amp;#39;, 12345.12,
  1.11, 2.22, 3.33,
  &amp;#39;char10&amp;#39;, &amp;#39;varchar10&amp;#39;, &amp;#39;text&amp;#39;,
  N&amp;#39;☺nchar12☺&amp;#39;, N&amp;#39;☺nvarchar12☺&amp;#39;, N&amp;#39;☺text☺&amp;#39;,
  GETDATE(), CAST(GETDATE() AS DATETIME2), CAST(GETDATE() AS SMALLDATETIME), CAST(GETDATE() AS DATE), CAST(GETDATE() AS TIME), SWITCHOFFSET(CAST(GETDATE() AS DATETIMEOFFSET), &amp;#39;-07:00&amp;#39;)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Example query with output:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT * FROM [mssql_types]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 500px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/static/img/docs/v51/mssql_table_query.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/static/img/docs/v51/mssql_table_query.png&#34;data-srcset=&#34;/static/img/docs/v51/mssql_table_query.png?w=320 320w, /static/img/docs/v51/mssql_table_query.png?w=550 550w, /static/img/docs/v51/mssql_table_query.png?w=750 750w, /static/img/docs/v51/mssql_table_query.png?w=900 900w, /static/img/docs/v51/mssql_table_query.png?w=1040 1040w, /static/img/docs/v51/mssql_table_query.png?w=1240 1240w, /static/img/docs/v51/mssql_table_query.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;&#34;width=&#34;559&#34;height=&#34;336&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/v51/mssql_table_query.png&#34;
            alt=&#34;&#34;width=&#34;559&#34;height=&#34;336&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;Use the keyword &lt;code&gt;AS&lt;/code&gt; to define an alias in your query to rename a column or table.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example query with output:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  c_bit AS [column1], c_tinyint AS [column2]
FROM
  [mssql_types]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 1489px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/static/img/docs/v51/mssql_table_result.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/static/img/docs/v51/mssql_table_result.png&#34;data-srcset=&#34;/static/img/docs/v51/mssql_table_result.png?w=320 320w, /static/img/docs/v51/mssql_table_result.png?w=550 550w, /static/img/docs/v51/mssql_table_result.png?w=750 750w, /static/img/docs/v51/mssql_table_result.png?w=900 900w, /static/img/docs/v51/mssql_table_result.png?w=1040 1040w, /static/img/docs/v51/mssql_table_result.png?w=1240 1240w, /static/img/docs/v51/mssql_table_result.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;&#34;width=&#34;2013&#34;height=&#34;167&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/v51/mssql_table_result.png&#34;
            alt=&#34;&#34;width=&#34;2013&#34;height=&#34;167&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;h2 id=&#34;time-series-queries&#34;&gt;Time series queries&lt;/h2&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Store timestamps in UTC to avoid issues with time shifts in Grafana when using non-UTC timezones.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;To create a time series query, set the &lt;strong&gt;Format&lt;/strong&gt; option in the query editor to &lt;strong&gt;Time series&lt;/strong&gt;. The query must include a column named &lt;code&gt;time&lt;/code&gt;, which should contain either an SQL &lt;code&gt;datetime&lt;/code&gt; value or a numeric value representing Unix epoch time in seconds. The result set must be sorted by the &lt;code&gt;time&lt;/code&gt; column for panels to visualize the data correctly.&lt;/p&gt;
&lt;p&gt;A time series query returns results in &lt;a href=&#34;/developers/plugin-tools/key-concepts/data-frames#wide-format&#34;&gt;wide data frame format&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Any column except &lt;code&gt;time&lt;/code&gt; or of the type &lt;code&gt;string&lt;/code&gt; transforms into value fields in the data frame query result.&lt;/li&gt;
&lt;li&gt;Any string column transforms into field labels in the data frame query result.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can enable macro support in the &lt;code&gt;SELECT&lt;/code&gt; clause to simplify time series query creation. Use the &lt;strong&gt;Data operations&lt;/strong&gt; drop-down to choose a macro such as &lt;code&gt;$\_\_timeGroup&lt;/code&gt; or &lt;code&gt;$\_\_timeGroupAlias&lt;/code&gt;, then select a time column from the Column drop-down and a time interval from the Interval drop-down. This generates a time-series query based on your selected time grouping.&lt;/p&gt;


&lt;div data-shared=&#34;datasources/sql-query-builder-macros.md&#34;&gt;
            &lt;h4 id=&#34;macros&#34;&gt;Macros&lt;/h4&gt;
&lt;p&gt;You can enable macros support in the select clause to create time-series queries.&lt;/p&gt;
&lt;p&gt;Use the &lt;strong&gt;Data operations&lt;/strong&gt; drop-down to select a macro like &lt;code&gt;$__timeGroup&lt;/code&gt; or &lt;code&gt;$__timeGroupAlias&lt;/code&gt;.
Select a time column from the &lt;strong&gt;Column&lt;/strong&gt; drop-down and a time interval from the &lt;strong&gt;Interval&lt;/strong&gt; drop-down to create a time-series query.&lt;/p&gt;
&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow&#34;
    style=&#34;max-width: 2378px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link captioned&#34;
        href=&#34;/media/docs/grafana/data-sources/screenshot-sql-builder-time-series-query.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload mb-0&#34;
          data-src=&#34;/media/docs/grafana/data-sources/screenshot-sql-builder-time-series-query.png&#34;data-srcset=&#34;/media/docs/grafana/data-sources/screenshot-sql-builder-time-series-query.png?w=320 320w, /media/docs/grafana/data-sources/screenshot-sql-builder-time-series-query.png?w=550 550w, /media/docs/grafana/data-sources/screenshot-sql-builder-time-series-query.png?w=750 750w, /media/docs/grafana/data-sources/screenshot-sql-builder-time-series-query.png?w=900 900w, /media/docs/grafana/data-sources/screenshot-sql-builder-time-series-query.png?w=1040 1040w, /media/docs/grafana/data-sources/screenshot-sql-builder-time-series-query.png?w=1240 1240w, /media/docs/grafana/data-sources/screenshot-sql-builder-time-series-query.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;SQL query builder time-series query&#34;width=&#34;2378&#34;height=&#34;1632&#34;title=&#34;SQL query builder time-series query&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/media/docs/grafana/data-sources/screenshot-sql-builder-time-series-query.png&#34;
            alt=&#34;SQL query builder time-series query&#34;width=&#34;2378&#34;height=&#34;1632&#34;title=&#34;SQL query builder time-series query&#34;class=&#34;docs-image--no-shadow&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;figcaption class=&#34;w-100p caption text-gray-13  &#34;&gt;SQL query builder time-series query&lt;/figcaption&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;You can also add custom value to the &lt;strong&gt;Data operations&lt;/strong&gt;.
For example, a function that&amp;rsquo;s not in the drop-down list.
This allows you to add any number of parameters.&lt;/p&gt;
&lt;/div&gt;

        
&lt;h3 id=&#34;create-a-metric-query&#34;&gt;Create a metric query&lt;/h3&gt;
&lt;p&gt;For backward compatibility, there&amp;rsquo;s an exception to the above rule for queries that return three columns and include a string column named &lt;code&gt;metric&lt;/code&gt;.
Instead of transforming the &lt;code&gt;metric&lt;/code&gt; column into field labels, it becomes the field name, and then the series name is formatted as the value of the &lt;code&gt;metric&lt;/code&gt; column.
See the example with the &lt;code&gt;metric&lt;/code&gt; column below.&lt;/p&gt;
&lt;p&gt;To optionally customize the default series name formatting, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/panels-visualizations/configure-standard-options/#display-name&#34;&gt;Standard options definitions&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example with &lt;code&gt;metric&lt;/code&gt; column:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(time_date_time, &amp;#39;5m&amp;#39;),
  min(&amp;#34;value_double&amp;#34;),
  &amp;#39;min&amp;#39; as metric
FROM test_data
WHERE $__timeFilter(time_date_time)
GROUP BY time
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Data frame result:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;text&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-text&#34;&gt;&amp;#43;---------------------&amp;#43;-----------------&amp;#43;
| Name: time          | Name: min       |
| Labels:             | Labels:         |
| Type: []time.Time   | Type: []float64 |
&amp;#43;---------------------&amp;#43;-----------------&amp;#43;
| 2020-01-02 03:05:00 | 3               |
| 2020-01-02 03:10:00 | 6               |
&amp;#43;---------------------&amp;#43;-----------------&amp;#43;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;time-series-query-examples&#34;&gt;Time series query examples&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Use the fill parameter in the $__timeGroupAlias macro to convert null values to be zero instead:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(createdAt, &amp;#39;5m&amp;#39;, 0),
  sum(value) as value,
  hostname
FROM test_data
WHERE
  $__timeFilter(createdAt)
GROUP BY
  time,
  hostname
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Given the data frame result in the following example and using the graph panel, you get two series named &lt;em&gt;value 10.0.1.1&lt;/em&gt; and &lt;em&gt;value 10.0.1.2&lt;/em&gt;. To render the series with a name of &lt;em&gt;10.0.1.1&lt;/em&gt; and &lt;em&gt;10.0.1.2&lt;/em&gt;, use a 
    &lt;a href=&#34;/docs/grafana/v13.2/panels-visualizations/configure-standard-options/#display-name&#34;&gt;Standard options definitions&lt;/a&gt; display name value of &lt;code&gt;${__field.labels.hostname}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Data frame result:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;text&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-text&#34;&gt;&amp;#43;---------------------&amp;#43;---------------------------&amp;#43;---------------------------&amp;#43;
| Name: time          | Name: value               | Name: value               |
| Labels:             | Labels: hostname=10.0.1.1 | Labels: hostname=10.0.1.2 |
| Type: []time.Time   | Type: []float64           | Type: []float64           |
&amp;#43;---------------------&amp;#43;---------------------------&amp;#43;---------------------------&amp;#43;
| 2020-01-02 03:05:00 | 3                         | 4                         |
| 2020-01-02 03:10:00 | 6                         | 7                         |
&amp;#43;---------------------&amp;#43;---------------------------&amp;#43;---------------------------&amp;#43;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Use multiple columns:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(time_date_time, &amp;#39;5m&amp;#39;),
  min(value_double) as min_value,
  max(value_double) as max_value
FROM test_data
WHERE $__timeFilter(time_date_time)
GROUP BY time
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Data frame result:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;text&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-text&#34;&gt;&amp;#43;---------------------&amp;#43;-----------------&amp;#43;-----------------&amp;#43;
| Name: time          | Name: min_value | Name: max_value |
| Labels:             | Labels:         | Labels:         |
| Type: []time.Time   | Type: []float64 | Type: []float64 |
&amp;#43;---------------------&amp;#43;-----------------&amp;#43;-----------------&amp;#43;
| 2020-01-02 03:04:00 | 3               | 4               |
| 2020-01-02 03:05:00 | 6               | 7               |
&amp;#43;---------------------&amp;#43;-----------------&amp;#43;-----------------&amp;#43;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;annotations&#34;&gt;Annotations&lt;/h2&gt;
&lt;p&gt;You can use Microsoft SQL Server queries as annotation sources to overlay events on your dashboard graphs. For detailed instructions, query examples, and best practices, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/annotations/&#34;&gt;Microsoft SQL Server annotations&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;use-stored-procedures&#34;&gt;Use stored procedures&lt;/h2&gt;
&lt;p&gt;Stored procedures have been verified to work with Grafana queries. However, note that there is no special handling or extended support for stored procedures, so some edge cases may not behave as expected.&lt;/p&gt;
&lt;p&gt;Stored procedures can be used in table, time series, and annotation queries, provided that the returned data matches the expected column names and formats described in the relevant previous sections in this document.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Grafana macro functions do not work inside stored procedures.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;figure
    class=&#34;figure-wrapper figure-wrapper__lightbox w-100p docs-image--no-shadow docs-image--right&#34;
    style=&#34;max-width: 1054px;&#34;
    itemprop=&#34;associatedMedia&#34;
    itemscope=&#34;&#34;
    itemtype=&#34;http://schema.org/ImageObject&#34;
  &gt;&lt;a
        class=&#34;lightbox-link&#34;
        href=&#34;/static/img/docs/v51/mssql_metrics_graph.png&#34;
        itemprop=&#34;contentUrl&#34;
      &gt;&lt;div class=&#34;img-wrapper w-100p h-auto&#34;&gt;&lt;img
          class=&#34;lazyload &#34;
          data-src=&#34;/static/img/docs/v51/mssql_metrics_graph.png&#34;data-srcset=&#34;/static/img/docs/v51/mssql_metrics_graph.png?w=320 320w, /static/img/docs/v51/mssql_metrics_graph.png?w=550 550w, /static/img/docs/v51/mssql_metrics_graph.png?w=750 750w, /static/img/docs/v51/mssql_metrics_graph.png?w=900 900w, /static/img/docs/v51/mssql_metrics_graph.png?w=1040 1040w, /static/img/docs/v51/mssql_metrics_graph.png?w=1240 1240w, /static/img/docs/v51/mssql_metrics_graph.png?w=1920 1920w&#34;data-sizes=&#34;auto&#34;alt=&#34;&#34;width=&#34;1054&#34;height=&#34;552&#34;/&gt;
        &lt;noscript&gt;
          &lt;img
            src=&#34;/static/img/docs/v51/mssql_metrics_graph.png&#34;
            alt=&#34;&#34;width=&#34;1054&#34;height=&#34;552&#34;class=&#34;docs-image--no-shadow docs-image--right&#34;/&gt;
        &lt;/noscript&gt;&lt;/div&gt;&lt;/a&gt;&lt;/figure&gt;
&lt;p&gt;For the following examples, the database table is defined in &lt;a href=&#34;#time-series-queries&#34;&gt;Time series queries&lt;/a&gt;. Let&amp;rsquo;s say that we want to visualize four series in a graph panel, such as all combinations of columns &lt;code&gt;valueOne&lt;/code&gt;, &lt;code&gt;valueTwo&lt;/code&gt; and &lt;code&gt;measurement&lt;/code&gt;. Graph panel to the right visualizes what we want to achieve. To solve this, you need to use two queries:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;First query:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroup(time, &amp;#39;5m&amp;#39;) as time,
  measurement &amp;#43; &amp;#39; - value one&amp;#39; as metric,
  avg(valueOne) as valueOne
FROM
  metric_values
WHERE
  $__timeFilter(time)
GROUP BY
  $__timeGroup(time, &amp;#39;5m&amp;#39;),
  measurement
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Second query:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroup(time, &amp;#39;5m&amp;#39;) as time,
  measurement &amp;#43; &amp;#39; - value two&amp;#39; as metric,
  avg(valueTwo) as valueTwo
FROM
  metric_values
GROUP BY
  $__timeGroup(time, &amp;#39;5m&amp;#39;),
  measurement
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;stored-procedure-with-epoch-time-format&#34;&gt;Stored procedure with epoch time format&lt;/h3&gt;
&lt;p&gt;You can define a stored procedure to return all the data needed to render multiple series (for example, 4) in a graph panel.&lt;/p&gt;
&lt;p&gt;In the following example, the stored procedure accepts two parameters, &lt;code&gt;@from&lt;/code&gt; and &lt;code&gt;@to&lt;/code&gt;, both of type &lt;code&gt;int&lt;/code&gt;. These parameters represent a time range (from/to) in epoch time format and are used to filter the results returned by the procedure.&lt;/p&gt;
&lt;p&gt;The query inside the procedure simulates the behavior of &lt;code&gt;$__timeGroup(time, &#39;5m&#39;)&lt;/code&gt; by grouping timestamps into 5-minute intervals. While the expressions for time grouping are somewhat verbose, they can be extracted into reusable SQL Server functions to simplify the procedure.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;CREATE PROCEDURE sp_test_epoch(
  @from int,
  @to 	int
)	AS
BEGIN
  SELECT
    cast(cast(DATEDIFF(second, {d &amp;#39;1970-01-01&amp;#39;}, DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), time))/600 as int)*600 as int) as time,
    measurement &amp;#43; &amp;#39; - value one&amp;#39; as metric,
    avg(valueOne) as value
  FROM
    metric_values
  WHERE
    time &amp;gt;= DATEADD(s, @from, &amp;#39;1970-01-01&amp;#39;) AND time &amp;lt;= DATEADD(s, @to, &amp;#39;1970-01-01&amp;#39;)
  GROUP BY
    cast(cast(DATEDIFF(second, {d &amp;#39;1970-01-01&amp;#39;}, DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), time))/600 as int)*600 as int),
    measurement
  UNION ALL
  SELECT
    cast(cast(DATEDIFF(second, {d &amp;#39;1970-01-01&amp;#39;}, DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), time))/600 as int)*600 as int) as time,
    measurement &amp;#43; &amp;#39; - value two&amp;#39; as metric,
    avg(valueTwo) as value
  FROM
    metric_values
  WHERE
    time &amp;gt;= DATEADD(s, @from, &amp;#39;1970-01-01&amp;#39;) AND time &amp;lt;= DATEADD(s, @to, &amp;#39;1970-01-01&amp;#39;)
  GROUP BY
    cast(cast(DATEDIFF(second, {d &amp;#39;1970-01-01&amp;#39;}, DATEADD(second, DATEDIFF(second,GETDATE(),GETUTCDATE()), time))/600 as int)*600 as int),
    measurement
  ORDER BY 1
END&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Then, in your graph panel, you can use the following query to call the stored procedure with the time range dynamically populated by Grafana:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;DECLARE
  @from int = $__unixEpochFrom(),
  @to int = $__unixEpochTo()

EXEC dbo.sp_test_epoch @from, @to&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This uses Grafana built-in macros to convert the selected time range into epoch time (&lt;code&gt;$__unixEpochFrom()&lt;/code&gt; and &lt;code&gt;$__unixEpochTo()&lt;/code&gt;), which are passed to the stored procedure as input parameters.&lt;/p&gt;
&lt;h3 id=&#34;stored-procedure-with-datetime-format&#34;&gt;Stored procedure with &lt;code&gt;datetime&lt;/code&gt; format&lt;/h3&gt;
&lt;p&gt;You can define a stored procedure to return all the data needed to render four series in a graph panel.&lt;/p&gt;
&lt;p&gt;In the following example, the stored procedure accepts two parameters, &lt;code&gt;@from&lt;/code&gt; and &lt;code&gt;@to&lt;/code&gt;, of the type &lt;code&gt;datetime&lt;/code&gt;. These parameters represent the selected time range and are used to filter the returned data.&lt;/p&gt;
&lt;p&gt;The query within the procedure mimics the behavior of &lt;code&gt;$__timeGroup(time, &#39;5m&#39;)&lt;/code&gt; by grouping data into 5-minute intervals. These expressions can be verbose, but you may extract them into reusable SQL Server functions for improved readability and maintainability.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;CREATE PROCEDURE sp_test_datetime(
  @from datetime,
  @to 	datetime
)	AS
BEGIN
  SELECT
    cast(cast(DATEDIFF(second, {d &amp;#39;1970-01-01&amp;#39;}, time)/600 as int)*600 as int) as time,
    measurement &amp;#43; &amp;#39; - value one&amp;#39; as metric,
    avg(valueOne) as value
  FROM
    metric_values
  WHERE
    time &amp;gt;= @from AND time &amp;lt;= @to
  GROUP BY
    cast(cast(DATEDIFF(second, {d &amp;#39;1970-01-01&amp;#39;}, time)/600 as int)*600 as int),
    measurement
  UNION ALL
  SELECT
    cast(cast(DATEDIFF(second, {d &amp;#39;1970-01-01&amp;#39;}, time)/600 as int)*600 as int) as time,
    measurement &amp;#43; &amp;#39; - value two&amp;#39; as metric,
    avg(valueTwo) as value
  FROM
    metric_values
  WHERE
    time &amp;gt;= @from AND time &amp;lt;= @to
  GROUP BY
    cast(cast(DATEDIFF(second, {d &amp;#39;1970-01-01&amp;#39;}, time)/600 as int)*600 as int),
    measurement
  ORDER BY 1
END&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To call this stored procedure from a graph panel, use the following query with Grafana built-in macros to populate the time range dynamically:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;DECLARE
  @from datetime = $__timeFrom(),
  @to datetime = $__timeTo()

EXEC dbo.sp_test_datetime @from, @to&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;next-steps&#34;&gt;Next steps&lt;/h2&gt;
&lt;p&gt;After building your queries, you can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/template-variables/&#34;&gt;Use template variables&lt;/a&gt; to create dynamic, reusable dashboards&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/annotations/&#34;&gt;Add annotations&lt;/a&gt; to overlay SQL Server events on your graphs&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/alerting/&#34;&gt;Set up alerting&lt;/a&gt; to create alert rules based on your query results&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/troubleshooting/&#34;&gt;Troubleshoot issues&lt;/a&gt; if queries return unexpected results&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="microsoft-sql-server-query-editor">Microsoft SQL Server query editor&lt;/h1>
&lt;p>The MSSQL query editor lets you write Transact-SQL queries directly in Grafana, with built-in macros and formatting options designed for time series and table visualizations. You can open it from
&lt;a href="/docs/grafana/v13.2/explore/">Explore&lt;/a> or from any dashboard panel in edit mode.&lt;/p></description></item><item><title>Microsoft SQL Server template variables</title><link>https://grafana.com/docs/grafana/v13.2/datasources/mssql/template-variables/</link><pubDate>Tue, 18 Aug 2026 10:15:08 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.2/datasources/mssql/template-variables/</guid><content><![CDATA[&lt;h1 id=&#34;microsoft-sql-server-template-variables&#34;&gt;Microsoft SQL Server template variables&lt;/h1&gt;
&lt;p&gt;Instead of hard-coding details such as server, application, and sensor names in metric queries, you can use variables.
Grafana displays these variables in drop-down select boxes at the top of the dashboard to help you change the data displayed in your dashboard.
Grafana refers to such variables as &lt;strong&gt;template variables&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For general information on using variables in Grafana, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/dashboards/variables/add-template-variables/&#34;&gt;Add variables&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For an introduction to templating and template variables, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/dashboards/variables/&#34;&gt;Templating&lt;/a&gt; and 
    &lt;a href=&#34;/docs/grafana/v13.2/dashboards/variables/add-template-variables/&#34;&gt;Add and manage variables&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;query-variable&#34;&gt;Query variable&lt;/h2&gt;
&lt;p&gt;A query variable in Grafana dynamically retrieves values from your data source using a query. With a query variable, you can write a SQL query that returns values such as measurement names, key names, or key values that are shown in a drop-down select box.&lt;/p&gt;
&lt;p&gt;For example, the following query returns all values from the &lt;code&gt;hostname&lt;/code&gt; column:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT hostname FROM host&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;A query can return multiple columns, and Grafana automatically generates a list using the values from those columns. For example, the following query returns values from both the &lt;code&gt;hostname&lt;/code&gt; and &lt;code&gt;hostname2&lt;/code&gt; columns, which are included in the variable&amp;rsquo;s drop-down list.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT [host].[hostname], [other_host].[hostname2] FROM host JOIN other_host ON [host].[city] = [other_host].[city]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can also create a key/value variable using a query that returns two columns named &lt;code&gt;__text&lt;/code&gt; and &lt;code&gt;__value&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The &lt;code&gt;__text&lt;/code&gt; column defines the label shown in the drop-down.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;code&gt;__value&lt;/code&gt; column defines the value passed to panel queries.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is useful when you want to display a user-friendly label (like a hostname) but use a different underlying value (like an ID).&lt;/p&gt;
&lt;p&gt;Note that the values in the &lt;code&gt;_text&lt;/code&gt; column should be unique. If there are duplicates, Grafana uses only the first matching entry.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT hostname __text, id __value FROM host&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;You can also create nested variables, where one variable depends on the value of another. For example, if you have a variable named &lt;code&gt;region&lt;/code&gt;, you can configure a &lt;code&gt;hosts&lt;/code&gt; variable to only show hosts from the selected region. If &lt;code&gt;region&lt;/code&gt; is a multi-value variable, use the &lt;code&gt;IN&lt;/code&gt; operator instead of &lt;code&gt;=&lt;/code&gt; to match against multiple selected values.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT hostname FROM host WHERE region IN ($region)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;use-variables-in-queries&#34;&gt;Use variables in queries&lt;/h2&gt;
&lt;p&gt;Grafana automatically quotes template variable values only when the template variable is a &lt;code&gt;multi-value&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;When using a multi-value variable, use the &lt;code&gt;IN&lt;/code&gt; comparison operator instead of &lt;code&gt;=&lt;/code&gt; to match against multiple values.&lt;/p&gt;
&lt;p&gt;Grafana supports two syntaxes for using variables in queries:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;$&amp;lt;varname&amp;gt;&lt;/code&gt; syntax&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example with a template variable named &lt;code&gt;hostname&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  atimestamp time,
  aint value
FROM table
WHERE $__timeFilter(atimestamp) and hostname in($hostname)
ORDER BY atimestamp&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;[[varname]]&lt;/code&gt; syntax&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example with a template variable named &lt;code&gt;hostname&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  atimestamp as time,
  aint as value
FROM table
WHERE $__timeFilter(atimestamp) and hostname in([[hostname]])
ORDER BY atimestamp&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;format-variables-for-sql-queries&#34;&gt;Format variables for SQL queries&lt;/h2&gt;
&lt;p&gt;When using template variables inside SQL queries, the formatting option you choose determines how Grafana renders the variable value. Choosing the correct format prevents SQL injection risks and avoids broken queries from incorrect quoting.&lt;/p&gt;
&lt;h3 id=&#34;use-sqlstring-for-safe-single-value-interpolation&#34;&gt;Use &lt;code&gt;sqlstring&lt;/code&gt; for safe single-value interpolation&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;${var:sqlstring}&lt;/code&gt; format wraps the variable value in single quotes and escapes any internal single quotes. This is the recommended approach for single-value variables used in &lt;code&gt;WHERE&lt;/code&gt; clauses:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT * FROM events
WHERE hostname = ${hostname:sqlstring}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If &lt;code&gt;hostname&lt;/code&gt; is set to &lt;code&gt;server01&lt;/code&gt;, this expands to:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT * FROM events
WHERE hostname = &amp;#39;server01&amp;#39;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;Don&amp;rsquo;t manually wrap variables in quotes (for example, &lt;code&gt;&#39;${var}&#39;&lt;/code&gt;). Since Grafana v11.3, multi-value variables are automatically quoted when used with the &lt;code&gt;IN&lt;/code&gt; operator. Manually adding quotes results in double-quoting (for example, &lt;code&gt;&#39;&#39;value&#39;&#39;&lt;/code&gt;), which breaks queries.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h3 id=&#34;multi-value-variable-formatting&#34;&gt;Multi-value variable formatting&lt;/h3&gt;
&lt;p&gt;When a variable allows multiple selections, Grafana provides several formatting options:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Format&lt;/th&gt;
              &lt;th&gt;Syntax&lt;/th&gt;
              &lt;th&gt;Output for selections &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;&lt;/th&gt;
              &lt;th&gt;Use case&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Default (auto-quoted)&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;$var&lt;/code&gt; or &lt;code&gt;${var}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;&#39;a&#39;,&#39;b&#39;&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;IN&lt;/code&gt; clauses (recommended)&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;sqlstring&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;${var:sqlstring}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;&#39;a&#39;&lt;/code&gt; (single value only)&lt;/td&gt;
              &lt;td&gt;Equality comparisons&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;csv&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;${var:csv}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;a,b&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Unquoted lists&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;singlequote&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;${var:singlequote}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;&#39;a&#39;,&#39;b&#39;&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Explicit single-quote wrapping&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;doublequote&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;${var:doublequote}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;&amp;quot;a&amp;quot;,&amp;quot;b&amp;quot;&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;MSSQL identifier quoting&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;pipe&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;${var:pipe}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;a|b&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Regex patterns&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;raw&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;${var:raw}&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;&lt;code&gt;a,b&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;No escaping (use with caution)&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;For multi-value variables in SQL &lt;code&gt;WHERE&lt;/code&gt; clauses, the default formatting with &lt;code&gt;IN&lt;/code&gt; is typically correct:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT * FROM events
WHERE hostname IN ($hostname)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If &lt;code&gt;hostname&lt;/code&gt; has values &lt;code&gt;server01&lt;/code&gt; and &lt;code&gt;server02&lt;/code&gt; selected, this expands to:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT * FROM events
WHERE hostname IN (&amp;#39;server01&amp;#39;,&amp;#39;server02&amp;#39;)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;disable-quoting-for-multi-value-variables&#34;&gt;Disable quoting for multi-value variables&lt;/h3&gt;
&lt;p&gt;To output multi-value variables without automatic quoting, use the &lt;code&gt;csv&lt;/code&gt; format:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;text&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-text&#34;&gt;${servers:csv}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This outputs the values as an unquoted comma-separated list. Use this only when you handle quoting yourself or when the values are numeric.&lt;/p&gt;
&lt;p&gt;Refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/dashboards/variables/variable-syntax/#advanced-variable-format-options&#34;&gt;Advanced variable format options&lt;/a&gt; for the full list of formatting options.&lt;/p&gt;
&lt;h2 id=&#34;handle-the-all-option-in-sql-queries&#34;&gt;Handle the &amp;ldquo;All&amp;rdquo; option in SQL queries&lt;/h2&gt;
&lt;p&gt;When a variable includes the &lt;strong&gt;All&lt;/strong&gt; option (enabled in variable settings), you need to handle the case where the user selects &amp;ldquo;All&amp;rdquo; differently from individual selections.&lt;/p&gt;
&lt;h3 id=&#34;pattern-use-a-custom-all-value-with-like&#34;&gt;Pattern: Use a custom &amp;ldquo;All&amp;rdquo; value with &lt;code&gt;LIKE&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Set the &lt;strong&gt;Custom all value&lt;/strong&gt; field in the variable settings to &lt;code&gt;%&lt;/code&gt;, then use &lt;code&gt;LIKE&lt;/code&gt; in your query:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT * FROM events
WHERE hostname LIKE ${hostname:sqlstring}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When the user selects &amp;ldquo;All&amp;rdquo;, &lt;code&gt;hostname&lt;/code&gt; resolves to &lt;code&gt;%&lt;/code&gt;, and the &lt;code&gt;LIKE &#39;%&#39;&lt;/code&gt; matches all rows. When a specific value is selected, &lt;code&gt;LIKE &#39;server01&#39;&lt;/code&gt; matches only that value.&lt;/p&gt;
&lt;h3 id=&#34;pattern-conditional-where-clause-with-all&#34;&gt;Pattern: Conditional &lt;code&gt;WHERE&lt;/code&gt; clause with &amp;ldquo;All&amp;rdquo;&lt;/h3&gt;
&lt;p&gt;For &lt;code&gt;IN&lt;/code&gt; clauses where &lt;code&gt;%&lt;/code&gt; doesn&amp;rsquo;t work, use a conditional approach. Set the &lt;strong&gt;Custom all value&lt;/strong&gt; to &lt;code&gt;ALL&lt;/code&gt;, then write:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT * FROM events
WHERE (
  ${hostname:raw} = &amp;#39;ALL&amp;#39;
  OR hostname IN ($hostname)
)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When the user selects &amp;ldquo;All&amp;rdquo;, the first condition is true and all rows match. When specific values are selected, the &lt;code&gt;IN&lt;/code&gt; clause filters normally.&lt;/p&gt;
&lt;h3 id=&#34;pattern-chained-variables-with-all&#34;&gt;Pattern: Chained variables with &amp;ldquo;All&amp;rdquo;&lt;/h3&gt;
&lt;p&gt;When you have chained (dependent) variables and the parent uses &amp;ldquo;All&amp;rdquo;, apply the same pattern. For example, if &lt;code&gt;region&lt;/code&gt; feeds into &lt;code&gt;hostname&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;Variable query for &lt;code&gt;hostname&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT hostname FROM host
WHERE (${region:raw} = &amp;#39;ALL&amp;#39; OR region IN ($region))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Panel query:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT $__timeGroupAlias(time, &amp;#39;5m&amp;#39;), COUNT(*) as count
FROM events
WHERE $__timeFilter(time)
  AND (${region:raw} = &amp;#39;ALL&amp;#39; OR region IN ($region))
  AND (${hostname:raw} = &amp;#39;ALL&amp;#39; OR hostname IN ($hostname))
GROUP BY $__timeGroup(time, &amp;#39;5m&amp;#39;)
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;conditional-sql-clauses&#34;&gt;Conditional SQL clauses&lt;/h2&gt;
&lt;p&gt;Grafana doesn&amp;rsquo;t have built-in support for conditionally omitting entire &lt;code&gt;WHERE&lt;/code&gt; clauses based on variable selection. Use one of these patterns to achieve conditional filtering.&lt;/p&gt;
&lt;h3 id=&#34;pattern-always-true-condition&#34;&gt;Pattern: Always-true condition&lt;/h3&gt;
&lt;p&gt;Use a condition that evaluates to true when the variable should be ignored:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT * FROM events
WHERE $__timeFilter(time)
  AND (${env:raw} = &amp;#39;ALL&amp;#39; OR environment IN ($env))
  AND (${sev:raw} = &amp;#39;ALL&amp;#39; OR severity IN ($sev))&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;pattern-case-expression-for-optional-filters&#34;&gt;Pattern: CASE expression for optional filters&lt;/h3&gt;
&lt;p&gt;For more complex scenarios, use a &lt;code&gt;CASE&lt;/code&gt; expression:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT * FROM events
WHERE $__timeFilter(time)
  AND 1 = CASE
    WHEN ${hostname:raw} = &amp;#39;ALL&amp;#39; THEN 1
    WHEN hostname IN ($hostname) THEN 1
    ELSE 0
  END&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;known-behaviors-and-limitations&#34;&gt;Known behaviors and limitations&lt;/h2&gt;
&lt;p&gt;Be aware of the following behaviors when using template variables with Microsoft SQL Server.&lt;/p&gt;
&lt;h3 id=&#34;automatic-quoting-in-multi-value-variables&#34;&gt;Automatic quoting in multi-value variables&lt;/h3&gt;
&lt;p&gt;Since Grafana v11.3, multi-value variables used with the &lt;code&gt;IN&lt;/code&gt; operator are automatically quoted. If you previously wrote &lt;code&gt;WHERE col IN (&#39;${var}&#39;)&lt;/code&gt; with manual quotes, remove the manual quotes and use &lt;code&gt;WHERE col IN ($var)&lt;/code&gt; instead.&lt;/p&gt;
&lt;h3 id=&#34;comments-inside-string-literals&#34;&gt;Comments inside string literals&lt;/h3&gt;
&lt;p&gt;The Grafana SQL query parser strips SQL comments (&lt;code&gt;--&lt;/code&gt; and &lt;code&gt;/* */&lt;/code&gt;) before macro interpolation. In some cases, &lt;code&gt;--&lt;/code&gt; inside a quoted string literal could be incorrectly interpreted as a comment. If your query contains strings with &lt;code&gt;--&lt;/code&gt;, verify the query expands correctly by clicking &lt;strong&gt;Generated SQL&lt;/strong&gt; after running the query.&lt;/p&gt;
&lt;h3 id=&#34;variables-in-alerting-queries&#34;&gt;Variables in alerting queries&lt;/h3&gt;
&lt;p&gt;Template variables are not supported in alerting queries. Grafana evaluates alert rules on the backend without dashboard context. If your dashboard query uses variables, create a separate alerting query with hard-coded values. For more information, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/alerting/#template-variables-not-supported&#34;&gt;Microsoft SQL Server alerting&lt;/a&gt;.&lt;/p&gt;
]]></content><description>&lt;h1 id="microsoft-sql-server-template-variables">Microsoft SQL Server template variables&lt;/h1>
&lt;p>Instead of hard-coding details such as server, application, and sensor names in metric queries, you can use variables.
Grafana displays these variables in drop-down select boxes at the top of the dashboard to help you change the data displayed in your dashboard.
Grafana refers to such variables as &lt;strong>template variables&lt;/strong>.&lt;/p></description></item><item><title>Microsoft SQL Server annotations</title><link>https://grafana.com/docs/grafana/v13.2/datasources/mssql/annotations/</link><pubDate>Tue, 18 Aug 2026 10:15:08 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.2/datasources/mssql/annotations/</guid><content><![CDATA[&lt;h1 id=&#34;microsoft-sql-server-annotations&#34;&gt;Microsoft SQL Server annotations&lt;/h1&gt;
&lt;p&gt;Annotations overlay event markers on your dashboard visualizations, helping you correlate metric behavior with events like deployments, incidents, or configuration changes. You can use the Microsoft SQL Server data source to create annotation queries that display SQL query results as annotation events.&lt;/p&gt;
&lt;p&gt;For general information about annotations, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/dashboards/build-dashboards/annotate-visualizations/&#34;&gt;Annotate visualizations&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;Before you create MSSQL annotations, ensure you have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A 
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/configure/&#34;&gt;configured Microsoft SQL Server data source&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;A table containing event data with at least a time column and a description column&lt;/li&gt;
&lt;li&gt;Familiarity with &lt;a href=&#34;https://learn.microsoft.com/en-us/sql/t-sql/language-reference&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;T-SQL&lt;/a&gt; query syntax&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;create-an-annotation-query&#34;&gt;Create an annotation query&lt;/h2&gt;
&lt;p&gt;To add a Microsoft SQL Server annotation to your dashboard:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Navigate to your dashboard and click &lt;strong&gt;Dashboard settings&lt;/strong&gt; (gear icon).&lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Annotations&lt;/strong&gt; in the left menu.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Add annotation query&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter a &lt;strong&gt;Name&lt;/strong&gt; for the annotation.&lt;/li&gt;
&lt;li&gt;Select your &lt;strong&gt;Microsoft SQL Server&lt;/strong&gt; data source from the &lt;strong&gt;Data source&lt;/strong&gt; drop-down.&lt;/li&gt;
&lt;li&gt;Write an SQL query that returns the required columns.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save dashboard&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;annotation-query-columns&#34;&gt;Annotation query columns&lt;/h2&gt;
&lt;p&gt;Your annotation query must return columns with specific names. Grafana uses these names to map query results to annotation fields.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Column&lt;/th&gt;
              &lt;th&gt;Required&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;time&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
              &lt;td&gt;The date/time of the event. Can be a native SQL date/time type or a Unix epoch value in seconds.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;timeend&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;The end time for region annotations. Same format as &lt;code&gt;time&lt;/code&gt;. Creates a shaded region instead of a line.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;text&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
              &lt;td&gt;The event description displayed in the annotation tooltip.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;tags&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;Comma-separated string used for event tags. Tags help categorize and filter annotations.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;example-annotation-with-epoch-time&#34;&gt;Example: Annotation with epoch time&lt;/h2&gt;
&lt;p&gt;Given a table that stores events with Unix epoch timestamps:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;CREATE TABLE [events] (
  time_sec bigint,
  description nvarchar(100),
  tags nvarchar(100),
)&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Query to display events as annotations:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  time_sec as time,
  description as [text],
  tags
FROM
  [events]
WHERE
  $__unixEpochFilter(time_sec)
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;$__unixEpochFilter&lt;/code&gt; macro automatically filters events to the dashboard&amp;rsquo;s selected time range.&lt;/p&gt;
&lt;h2 id=&#34;example-region-annotation-with-start-and-end-times&#34;&gt;Example: Region annotation with start and end times&lt;/h2&gt;
&lt;p&gt;To display annotations as shaded regions (spanning a duration), include both &lt;code&gt;time&lt;/code&gt; and &lt;code&gt;timeend&lt;/code&gt; columns:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  time_sec as time,
  time_end_sec as timeend,
  description as [text],
  tags
FROM
  [events]
WHERE
  $__unixEpochFilter(time_sec)
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;example-annotation-with-native-datetime-column&#34;&gt;Example: Annotation with native &lt;code&gt;datetime&lt;/code&gt; column&lt;/h2&gt;
&lt;p&gt;If your table uses native SQL &lt;code&gt;datetime&lt;/code&gt; or &lt;code&gt;datetime2&lt;/code&gt; columns instead of epoch values:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  time,
  measurement as text,
  convert(varchar, valueOne) &amp;#43; &amp;#39;,&amp;#39; &amp;#43; convert(varchar, valueTwo) as tags
FROM
  metric_values
WHERE
  $__timeFilter(time)
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;$__timeFilter&lt;/code&gt; macro works with native SQL date/time types and filters to the dashboard time range.&lt;/p&gt;
&lt;h2 id=&#34;example-deployment-annotations&#34;&gt;Example: Deployment annotations&lt;/h2&gt;
&lt;p&gt;Display deployment events on your graphs:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  deployed_at as time,
  &amp;#39;Deployed &amp;#39; &amp;#43; version &amp;#43; &amp;#39; to &amp;#39; &amp;#43; environment as [text],
  environment as tags
FROM
  [deployments]
WHERE
  $__timeFilter(deployed_at)
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;example-maintenance-window-annotations&#34;&gt;Example: Maintenance window annotations&lt;/h2&gt;
&lt;p&gt;Display maintenance windows as shaded regions:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  start_time as time,
  end_time as timeend,
  &amp;#39;Maintenance: &amp;#39; &amp;#43; description as [text],
  &amp;#39;maintenance&amp;#39; as tags
FROM
  [maintenance_windows]
WHERE
  $__timeFilter(start_time)
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;use-template-variables&#34;&gt;Use template variables&lt;/h2&gt;
&lt;p&gt;You can use 
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/template-variables/&#34;&gt;template variables&lt;/a&gt; in your annotation queries to make them dynamic. For example, filter events by a selected server:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  time_sec as time,
  description as [text],
  tags
FROM
  [events]
WHERE
  $__unixEpochFilter(time_sec)
  AND server IN ($server)
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;macros&#34;&gt;Macros&lt;/h2&gt;
&lt;p&gt;Use these macros in your annotation queries to filter by the dashboard time range:&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Macro&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__timeFilter(column)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Filters by time range using a native SQL &lt;code&gt;datetime&lt;/code&gt;/&lt;code&gt;datetime2&lt;/code&gt; column.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;code&gt;$__unixEpochFilter(column)&lt;/code&gt;&lt;/td&gt;
              &lt;td&gt;Filters by time range using a column with Unix epoch timestamps.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;p&gt;For the full list of available macros, refer to the 
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/query-editor/#macros&#34;&gt;Microsoft SQL Server query editor&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;best-practices&#34;&gt;Best practices&lt;/h2&gt;
&lt;p&gt;Follow these best practices when creating Microsoft SQL Server annotations:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Use time filters:&lt;/strong&gt; Always include &lt;code&gt;$__timeFilter()&lt;/code&gt; or &lt;code&gt;$__unixEpochFilter()&lt;/code&gt; to limit results to the dashboard time range.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Keep queries efficient:&lt;/strong&gt; Add indexes on time columns and filter columns to improve query performance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use meaningful text:&lt;/strong&gt; Include descriptive information in the &lt;code&gt;text&lt;/code&gt; column to make annotations useful at a glance.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Organize with tags:&lt;/strong&gt; Use consistent tag values to categorize annotations and enable filtering.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test queries first:&lt;/strong&gt; Verify your query returns expected results in Explore before adding it as an annotation.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;get-help&#34;&gt;Get help&lt;/h2&gt;
&lt;p&gt;If your annotations aren&amp;rsquo;t appearing or behaving as expected, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/troubleshooting/&#34;&gt;Troubleshoot Microsoft SQL Server data source issues&lt;/a&gt; for common solutions.&lt;/p&gt;
]]></content><description>&lt;h1 id="microsoft-sql-server-annotations">Microsoft SQL Server annotations&lt;/h1>
&lt;p>Annotations overlay event markers on your dashboard visualizations, helping you correlate metric behavior with events like deployments, incidents, or configuration changes. You can use the Microsoft SQL Server data source to create annotation queries that display SQL query results as annotation events.&lt;/p></description></item><item><title>Microsoft SQL Server alerting</title><link>https://grafana.com/docs/grafana/v13.2/datasources/mssql/alerting/</link><pubDate>Tue, 18 Aug 2026 10:15:08 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.2/datasources/mssql/alerting/</guid><content><![CDATA[&lt;h1 id=&#34;microsoft-sql-server-alerting&#34;&gt;Microsoft SQL Server alerting&lt;/h1&gt;
&lt;p&gt;You can use Grafana Alerting with Microsoft SQL Server to create alerts based on your SQL Server data. This allows you to monitor metrics, detect anomalies, and receive notifications when specific conditions are met.&lt;/p&gt;
&lt;p&gt;For general information about Grafana Alerting, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/alerting/&#34;&gt;Grafana Alerting&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;before-you-begin&#34;&gt;Before you begin&lt;/h2&gt;
&lt;p&gt;Before creating alerts with Microsoft SQL Server, ensure you have:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A 
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/configure/&#34;&gt;configured Microsoft SQL Server data source&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Appropriate permissions to create alert rules&lt;/li&gt;
&lt;li&gt;Understanding of the metrics you want to monitor&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;supported-query-types&#34;&gt;Supported query types&lt;/h2&gt;
&lt;p&gt;Microsoft SQL Server alerting works with &lt;strong&gt;time series queries&lt;/strong&gt; that return numeric data over time. Table-formatted queries are not supported in alert rule conditions.&lt;/p&gt;
&lt;p&gt;To create a valid alert query:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Include a &lt;code&gt;time&lt;/code&gt; column that returns an SQL &lt;code&gt;datetime&lt;/code&gt;/&lt;code&gt;datetime2&lt;/code&gt; or a Unix epoch timestamp&lt;/li&gt;
&lt;li&gt;Return numeric values for the metrics you want to alert on&lt;/li&gt;
&lt;li&gt;Sort results by the time column&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For more information on writing time series queries, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/query-editor/&#34;&gt;Microsoft SQL Server query editor&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;query-format-requirements&#34;&gt;Query format requirements&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Query format&lt;/th&gt;
              &lt;th&gt;Alerting support&lt;/th&gt;
              &lt;th&gt;Notes&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Time series&lt;/td&gt;
              &lt;td&gt;Yes&lt;/td&gt;
              &lt;td&gt;Required for alerting&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Table&lt;/td&gt;
              &lt;td&gt;No&lt;/td&gt;
              &lt;td&gt;Convert to time series format for alerts&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;create-an-alert-rule&#34;&gt;Create an alert rule&lt;/h2&gt;
&lt;p&gt;To create an alert rule using Microsoft SQL Server:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Navigate to &lt;strong&gt;Alerting&lt;/strong&gt; &amp;gt; &lt;strong&gt;Alert rules&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;New alert rule&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Enter a name for the alert rule.&lt;/li&gt;
&lt;li&gt;Select your &lt;strong&gt;Microsoft SQL Server&lt;/strong&gt; data source.&lt;/li&gt;
&lt;li&gt;Build your query using the query editor:
&lt;ul&gt;
&lt;li&gt;Set the &lt;strong&gt;Format&lt;/strong&gt; to &lt;strong&gt;Time series&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Include a time column using the &lt;code&gt;$__timeGroup()&lt;/code&gt; or &lt;code&gt;$__timeGroupAlias()&lt;/code&gt; macro.&lt;/li&gt;
&lt;li&gt;Add numeric columns for the values to monitor.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;$__timeFilter()&lt;/code&gt; to filter data by the evaluation time range.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Configure the alert condition (for example, when the average is above a threshold).&lt;/li&gt;
&lt;li&gt;Set the evaluation interval and pending period.&lt;/li&gt;
&lt;li&gt;Configure notifications and labels.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save rule&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For detailed instructions, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/alerting/alerting-rules/create-grafana-managed-rule/&#34;&gt;Create a Grafana-managed alert rule&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;example-alert-queries&#34;&gt;Example alert queries&lt;/h2&gt;
&lt;p&gt;The following examples show common alerting scenarios with Microsoft SQL Server.&lt;/p&gt;
&lt;h3 id=&#34;alert-on-high-error-count&#34;&gt;Alert on high error count&lt;/h3&gt;
&lt;p&gt;Monitor the number of errors over time:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(created_at, &amp;#39;1m&amp;#39;),
  COUNT(*) AS error_count
FROM error_logs
WHERE $__timeFilter(created_at)
  AND level = &amp;#39;error&amp;#39;
GROUP BY $__timeGroup(created_at, &amp;#39;1m&amp;#39;)
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Condition:&lt;/strong&gt; When &lt;code&gt;error_count&lt;/code&gt; is above 100.&lt;/p&gt;
&lt;h3 id=&#34;alert-on-average-response-time&#34;&gt;Alert on average response time&lt;/h3&gt;
&lt;p&gt;Monitor API response times:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(request_time, &amp;#39;5m&amp;#39;),
  AVG(response_time_ms) AS avg_response_time
FROM api_requests
WHERE $__timeFilter(request_time)
GROUP BY $__timeGroup(request_time, &amp;#39;5m&amp;#39;)
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Condition:&lt;/strong&gt; When &lt;code&gt;avg_response_time&lt;/code&gt; is above 500 (milliseconds).&lt;/p&gt;
&lt;h3 id=&#34;alert-on-low-order-volume&#34;&gt;Alert on low order volume&lt;/h3&gt;
&lt;p&gt;Detect drops in order activity:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(order_date, &amp;#39;1h&amp;#39;),
  COUNT(*) AS order_count
FROM orders
WHERE $__timeFilter(order_date)
GROUP BY $__timeGroup(order_date, &amp;#39;1h&amp;#39;)
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Condition:&lt;/strong&gt; When &lt;code&gt;order_count&lt;/code&gt; is below 10.&lt;/p&gt;
&lt;h3 id=&#34;alert-on-high-cpu-utilization&#34;&gt;Alert on high CPU utilization&lt;/h3&gt;
&lt;p&gt;Monitor server resource metrics:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  $__timeGroupAlias(recorded_at, &amp;#39;5m&amp;#39;),
  AVG(cpu_percent) AS avg_cpu
FROM sys_metrics
WHERE $__timeFilter(recorded_at)
GROUP BY $__timeGroup(recorded_at, &amp;#39;5m&amp;#39;)
ORDER BY 1&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Condition:&lt;/strong&gt; When &lt;code&gt;avg_cpu&lt;/code&gt; is above 85.&lt;/p&gt;
&lt;h2 id=&#34;limitations&#34;&gt;Limitations&lt;/h2&gt;
&lt;p&gt;When using Microsoft SQL Server with Grafana Alerting, be aware of the following limitations.&lt;/p&gt;
&lt;h3 id=&#34;template-variables-not-supported&#34;&gt;Template variables not supported&lt;/h3&gt;
&lt;p&gt;Alert queries cannot contain template variables. Grafana evaluates alert rules on the backend without dashboard context, so variables like &lt;code&gt;$hostname&lt;/code&gt; or &lt;code&gt;$environment&lt;/code&gt; aren&amp;rsquo;t resolved.&lt;/p&gt;
&lt;p&gt;If your dashboard query uses template variables, create a separate query for alerting with hard-coded values.&lt;/p&gt;
&lt;h3 id=&#34;table-format-not-supported&#34;&gt;Table format not supported&lt;/h3&gt;
&lt;p&gt;Queries using the &lt;strong&gt;Table&lt;/strong&gt; format cannot be used for alerting. Set the query format to &lt;strong&gt;Time series&lt;/strong&gt; and ensure your query returns a time column.&lt;/p&gt;
&lt;h3 id=&#34;query-timeout&#34;&gt;Query timeout&lt;/h3&gt;
&lt;p&gt;Complex queries with large datasets may time out during alert evaluation. Optimize queries for alerting by:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Adding appropriate &lt;code&gt;WHERE&lt;/code&gt; clauses to limit data&lt;/li&gt;
&lt;li&gt;Using indexes on time and filter columns&lt;/li&gt;
&lt;li&gt;Reducing the time range evaluated&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;current-user-authentication-not-supported&#34;&gt;Current User authentication not supported&lt;/h3&gt;
&lt;p&gt;If your data source uses Azure Entra ID &lt;strong&gt;Current User&lt;/strong&gt; authentication, alerting, reporting, and recorded queries are not supported. These features require backend-level credentials that don&amp;rsquo;t rely on a specific user&amp;rsquo;s session.&lt;/p&gt;
&lt;h2 id=&#34;best-practices&#34;&gt;Best practices&lt;/h2&gt;
&lt;p&gt;Follow these best practices when creating Microsoft SQL Server alerts:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Use time series format:&lt;/strong&gt; Always set the query format to time series for alert queries.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Include time filters:&lt;/strong&gt; Use the &lt;code&gt;$__timeFilter()&lt;/code&gt; macro to limit data to the evaluation window.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use MSSQL macros:&lt;/strong&gt; Prefer &lt;code&gt;$__timeGroupAlias()&lt;/code&gt; and &lt;code&gt;$__timeGroup()&lt;/code&gt; over manual time-bucketing expressions.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Optimize queries:&lt;/strong&gt; Add indexes on columns used in &lt;code&gt;WHERE&lt;/code&gt; clauses and &lt;code&gt;GROUP BY&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Test queries first:&lt;/strong&gt; Verify your query returns expected results in Explore before creating an alert.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Set realistic thresholds:&lt;/strong&gt; Base alert thresholds on historical data patterns.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Use meaningful names:&lt;/strong&gt; Give alert rules descriptive names that indicate what they monitor.&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="microsoft-sql-server-alerting">Microsoft SQL Server alerting&lt;/h1>
&lt;p>You can use Grafana Alerting with Microsoft SQL Server to create alerts based on your SQL Server data. This allows you to monitor metrics, detect anomalies, and receive notifications when specific conditions are met.&lt;/p></description></item><item><title>Troubleshoot Microsoft SQL Server data source issues</title><link>https://grafana.com/docs/grafana/v13.2/datasources/mssql/troubleshooting/</link><pubDate>Tue, 18 Aug 2026 10:15:08 +0000</pubDate><guid>https://grafana.com/docs/grafana/v13.2/datasources/mssql/troubleshooting/</guid><content><![CDATA[&lt;h1 id=&#34;troubleshoot-microsoft-sql-server-data-source-issues&#34;&gt;Troubleshoot Microsoft SQL Server data source issues&lt;/h1&gt;
&lt;p&gt;This document provides solutions to common issues you may encounter when configuring or using the Microsoft SQL Server (MSSQL) data source in Grafana.&lt;/p&gt;
&lt;h2 id=&#34;configuration-errors&#34;&gt;Configuration errors&lt;/h2&gt;
&lt;p&gt;These errors occur when setting up or accessing the data source configuration in Grafana.&lt;/p&gt;
&lt;h3 id=&#34;configuration-form-not-displaying&#34;&gt;Configuration form not displaying&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Symptoms:&lt;/strong&gt; The data source settings page shows only &lt;strong&gt;Delete&lt;/strong&gt; and &lt;strong&gt;Back&lt;/strong&gt; buttons with no configuration fields.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The logged-in user has insufficient permissions to configure data sources. Only users with the &lt;code&gt;Organization administrator&lt;/code&gt; role (or a custom RBAC role with &lt;code&gt;datasources:write&lt;/code&gt; permissions) can access the data source configuration form.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Ask an organization administrator to grant you the &lt;code&gt;Organization administrator&lt;/code&gt; role, or assign you a custom RBAC role with data source write permissions.&lt;/li&gt;
&lt;li&gt;Alternatively, ask an administrator to configure the data source on your behalf or use 
    &lt;a href=&#34;/docs/grafana/v13.2/administration/provisioning/&#34;&gt;provisioning&lt;/a&gt; to define the data source in YAML.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;connection-errors&#34;&gt;Connection errors&lt;/h2&gt;
&lt;p&gt;These errors occur when Grafana cannot establish or maintain a connection to the Microsoft SQL Server.&lt;/p&gt;
&lt;h3 id=&#34;unable-to-connect-to-the-server&#34;&gt;Unable to connect to the server&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;Unable to open tcp connection&lt;/code&gt; or &lt;code&gt;dial tcp: connection refused&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Grafana cannot establish a network connection to the SQL Server.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify that the SQL Server is running and accessible.&lt;/li&gt;
&lt;li&gt;Check that the host and port are correct in the data source configuration. The default SQL Server port is &lt;code&gt;1433&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Ensure there are no firewall rules blocking the connection between Grafana and SQL Server.&lt;/li&gt;
&lt;li&gt;Verify that SQL Server is configured to allow remote connections.&lt;/li&gt;
&lt;li&gt;For Grafana Cloud, ensure you have configured &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;Private data source connect&lt;/a&gt; if your SQL Server instance is not publicly accessible.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;connection-timeout&#34;&gt;Connection timeout&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Connection timed out&amp;rdquo; or &amp;ldquo;I/O timeout&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The connection to SQL Server timed out before receiving a response.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check the network latency between Grafana and SQL Server.&lt;/li&gt;
&lt;li&gt;Verify that SQL Server is not overloaded or experiencing performance issues.&lt;/li&gt;
&lt;li&gt;Increase the &lt;strong&gt;Connection timeout&lt;/strong&gt; setting in the data source configuration under &lt;strong&gt;Additional settings&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Check if any network devices (load balancers, proxies) are timing out the connection.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;encryption-related-connection-failures&#34;&gt;Encryption-related connection failures&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;TLS handshake failed&amp;rdquo; or &amp;ldquo;certificate verify failed&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; There is a mismatch between the encryption settings in Grafana and what the SQL Server supports or requires.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;For older versions of SQL Server (2008, 2008R2), set the &lt;strong&gt;Encrypt&lt;/strong&gt; option to &lt;strong&gt;Disable&lt;/strong&gt; or &lt;strong&gt;False&lt;/strong&gt; in the data source configuration.&lt;/li&gt;
&lt;li&gt;If Encrypt is &lt;strong&gt;True&lt;/strong&gt;, verify that the SQL Server has a valid TLS certificate.&lt;/li&gt;
&lt;li&gt;Check that the certificate is trusted by the Grafana server (either in the system CA bundle or specified in &lt;strong&gt;TLS/SSL Root Certificate&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;If the certificate&amp;rsquo;s hostname doesn&amp;rsquo;t match the configured &lt;strong&gt;Host&lt;/strong&gt; value (for example, when using a load balancer or PDC), set &lt;strong&gt;Hostname in server certificate&lt;/strong&gt; to match the certificate&amp;rsquo;s CN or SAN.&lt;/li&gt;
&lt;li&gt;As a temporary workaround for testing, enable &lt;strong&gt;Skip TLS Verify&lt;/strong&gt; (not recommended for production).&lt;/li&gt;
&lt;li&gt;Ensure you&amp;rsquo;re using the latest available service pack for your SQL Server version for optimal compatibility.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;tls-handshake-failures-with-fips-enabled-grafana&#34;&gt;TLS handshake failures with FIPS-enabled Grafana&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;TLS handshake failed&amp;rdquo; or &amp;ldquo;no cipher suite supported by both client and server&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Grafana builds using BoringCrypto (FIPS-compliant builds) enforce FIPS 140-3 cipher requirements. SQL Server instances that only support older cipher suites (TLS 1.0, RC4, or 3DES) are incompatible with these builds.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Upgrade the SQL Server instance to support TLS 1.2 with FIPS-approved cipher suites (AES-based).&lt;/li&gt;
&lt;li&gt;On the SQL Server host, verify TLS 1.2 is enabled in the Windows registry or SQL Server Network Configuration.&lt;/li&gt;
&lt;li&gt;If you cannot upgrade SQL Server, use a non-FIPS Grafana build.&lt;/li&gt;
&lt;li&gt;Verify which TLS versions your SQL Server supports by checking the SQL Server error log for &amp;ldquo;TLS handshake&amp;rdquo; entries.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;tls-certificate-errors-through-pdc&#34;&gt;TLS certificate errors through PDC&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;certificate verify failed&amp;rdquo; or &amp;ldquo;x509: certificate signed by unknown authority&amp;rdquo; when connecting through Private data source connect&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The SQL Server&amp;rsquo;s TLS certificate must be verifiable from the PDC agent&amp;rsquo;s perspective, not from Grafana Cloud. If the SQL Server uses a private CA certificate, the PDC agent host must trust that CA.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Install the private CA certificate on the PDC agent host&amp;rsquo;s system trust store.&lt;/li&gt;
&lt;li&gt;Alternatively, specify the CA certificate path in the data source&amp;rsquo;s &lt;strong&gt;TLS/SSL Root Certificate&lt;/strong&gt; field (the path must be accessible from the PDC agent, not from Grafana Cloud).&lt;/li&gt;
&lt;li&gt;If the certificate&amp;rsquo;s hostname doesn&amp;rsquo;t match what the PDC agent sees, set &lt;strong&gt;Hostname in server certificate&lt;/strong&gt; to the correct value.&lt;/li&gt;
&lt;li&gt;Verify the certificate is valid (not expired) from the PDC agent host: &lt;code&gt;openssl s_client -connect &amp;lt;SQL_SERVER_HOST&amp;gt;:1433 -starttls mssql&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;named-instance-connection-issues&#34;&gt;Named instance connection issues&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Cannot connect to named instance&amp;rdquo; or connection fails when using instance name&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Grafana cannot resolve the SQL Server named instance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use the format &lt;code&gt;hostname\instancename&lt;/code&gt; or &lt;code&gt;hostname\instancename,port&lt;/code&gt; in the &lt;strong&gt;Host&lt;/strong&gt; field.&lt;/li&gt;
&lt;li&gt;Verify that the SQL Server Browser service is running on the SQL Server machine.&lt;/li&gt;
&lt;li&gt;If the Browser service is unavailable, specify the port number directly: &lt;code&gt;hostname,port&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Check that UDP port 1434 is open if using the SQL Server Browser service.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;private-data-source-connect-pdc-errors&#34;&gt;Private data source connect (PDC) errors&lt;/h2&gt;
&lt;p&gt;These errors occur when using Grafana Cloud with Private data source connect to reach an on-premises or private-network SQL Server.&lt;/p&gt;
&lt;h3 id=&#34;no-such-host-when-connecting-through-pdc&#34;&gt;&amp;ldquo;No such host&amp;rdquo; when connecting through PDC&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;dial tcp: lookup sqlserver.internal.example.com: no such host&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The PDC agent cannot resolve the SQL Server hostname from its network. This commonly occurs when:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The hostname in the data source configuration is a public DNS name that doesn&amp;rsquo;t resolve inside the private network.&lt;/li&gt;
&lt;li&gt;The PDC agent host doesn&amp;rsquo;t have access to the internal DNS server.&lt;/li&gt;
&lt;li&gt;A cluster or Availability Group Listener DNS entry is misconfigured.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;In the data source &lt;strong&gt;Host&lt;/strong&gt; field, use the hostname as resolvable from the PDC agent&amp;rsquo;s network (for example, the internal FQDN or IP address, not a public DNS name).&lt;/li&gt;
&lt;li&gt;Verify the PDC agent host can resolve the hostname: run &lt;code&gt;nslookup &amp;lt;SQL_SERVER_HOST&amp;gt;&lt;/code&gt; from the agent machine.&lt;/li&gt;
&lt;li&gt;If using a cluster or Availability Group Listener, confirm the listener DNS record exists and resolves to the correct IP from the agent&amp;rsquo;s network.&lt;/li&gt;
&lt;li&gt;Check that the PDC agent host has the correct DNS servers configured.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;pdc-connection-breaks-after-maintenance-or-ip-changes&#34;&gt;PDC connection breaks after maintenance or IP changes&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The PDC SSH tunnel endpoint IP changed after infrastructure maintenance, breaking the established connection.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Restart the PDC agent service to re-establish the SSH tunnel with the updated endpoint.&lt;/li&gt;
&lt;li&gt;Verify the PDC agent status shows a healthy connection in &lt;strong&gt;Connections&lt;/strong&gt; &amp;gt; &lt;strong&gt;Private data source connect&lt;/strong&gt; in your Grafana Cloud stack.&lt;/li&gt;
&lt;li&gt;If your network uses IP-based firewall rules for outbound traffic, update the allowlist. PDC endpoint IP addresses can change during maintenance windows.&lt;/li&gt;
&lt;li&gt;Consider using DNS-based allowlisting instead of IP-based rules where possible to avoid future disruptions.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;credentials-not-persisting-with-pdc-enabled&#34;&gt;Credentials not persisting with PDC enabled&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; A known issue can cause the data source username to not persist when PDC is enabled.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;After enabling PDC, save the data source configuration first, then re-enter the username and password and save again.&lt;/li&gt;
&lt;li&gt;Click &lt;strong&gt;Save &amp;amp; test&lt;/strong&gt; to verify the credentials are stored and the connection succeeds.&lt;/li&gt;
&lt;li&gt;If the issue persists, try disabling PDC, saving credentials, then re-enabling PDC.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;cannot-connect-to-private-sql-server-from-grafana-cloud&#34;&gt;Cannot connect to private SQL Server from Grafana Cloud&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Attempting to connect to an on-premises or private-network SQL Server from Grafana Cloud without PDC configured.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Grafana Cloud requires &lt;a href=&#34;/docs/grafana-cloud/connect-externally-hosted/private-data-source-connect/&#34;&gt;Private data source connect (PDC)&lt;/a&gt; for any SQL Server that isn&amp;rsquo;t publicly accessible.&lt;/li&gt;
&lt;li&gt;Firewall allowlisting alone doesn&amp;rsquo;t work because Grafana Cloud data source connections don&amp;rsquo;t use static IP addresses.&lt;/li&gt;
&lt;li&gt;Install and configure a PDC agent on a host in your private network that can reach the SQL Server on port 1433.&lt;/li&gt;
&lt;li&gt;Ensure the PDC agent host allows outbound connections on port 22 to the Grafana Cloud PDC endpoint.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For setup instructions, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/configure/#connect-to-on-premises-sql-server-from-grafana-cloud&#34;&gt;Connect to on-premises SQL Server from Grafana Cloud&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;authentication-errors&#34;&gt;Authentication errors&lt;/h2&gt;
&lt;p&gt;These errors occur when there are issues with authentication credentials or permissions.&lt;/p&gt;
&lt;h3 id=&#34;login-failed-for-user&#34;&gt;Login failed for user&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Login failed for user &amp;lsquo;username&amp;rsquo;&amp;rdquo; or &amp;ldquo;Authentication failed&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The authentication credentials are invalid or the user doesn&amp;rsquo;t have permission to access the database.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify that the username and password are correct.&lt;/li&gt;
&lt;li&gt;Check that the user exists in SQL Server and is enabled.&lt;/li&gt;
&lt;li&gt;Ensure the user has access to the specified database.&lt;/li&gt;
&lt;li&gt;For Windows Authentication, verify that the credentials are in the correct format (&lt;code&gt;DOMAIN\User&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Check that the SQL Server authentication mode allows the type of login you&amp;rsquo;re using (SQL Server Authentication, Windows Authentication, or Mixed Mode).&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;login-failed-for-user--empty-username&#34;&gt;Login failed for user &amp;rsquo;&amp;rsquo; (empty username)&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Login failed for user &amp;lsquo;&amp;rsquo;&amp;quot;—the saved username appears blank when Grafana connects to SQL Server.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; A known issue on certain Grafana release channels caused the SQL Server Authentication username to appear saved in the UI but send an empty string to the server during connection. This was identified on the &amp;ldquo;fast&amp;rdquo; release channel.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Switch to the &amp;ldquo;steady&amp;rdquo; release channel if you&amp;rsquo;re on &amp;ldquo;fast&amp;rdquo; and encounter this issue.&lt;/li&gt;
&lt;li&gt;After upgrading or switching channels, open the data source configuration, re-enter the username and password, and click &lt;strong&gt;Save &amp;amp; test&lt;/strong&gt; to confirm the credentials are stored correctly.&lt;/li&gt;
&lt;li&gt;If the issue persists after re-saving, clear your browser cache and try again.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;connection-fails-when-password-contains-special-characters&#34;&gt;Connection fails when password contains special characters&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Login failed for user&amp;rdquo; or &amp;ldquo;Connection string parse error&amp;rdquo; when credentials contain semicolons (&lt;code&gt;;&lt;/code&gt;) or closing braces (&lt;code&gt;}&lt;/code&gt;)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; In Grafana versions prior to v13.0, semicolons and closing braces in usernames or passwords were not properly escaped in the MSSQL connection string, causing authentication failures.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Upgrade to Grafana v13.0 or later, which correctly handles these special characters.&lt;/li&gt;
&lt;li&gt;If you cannot upgrade, change the SQL Server password to avoid &lt;code&gt;;&lt;/code&gt; and &lt;code&gt;}&lt;/code&gt; characters.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;access-denied-to-database&#34;&gt;Access denied to database&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &lt;code&gt;Cannot open database &#39;dbname&#39; requested by the login&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The authenticated user doesn&amp;rsquo;t have permission to access the specified database.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Verify that the database name is correct in the data source configuration.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Ensure the user is mapped to the database with appropriate permissions.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Grant at least &lt;code&gt;SELECT&lt;/code&gt; permission on the required tables:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;USE [your_database]
GRANT SELECT ON dbo.YourTable TO [your_user]&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Check that the user doesn&amp;rsquo;t have any conflicting permissions from the public role.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;!-- vale Grafana.Spelling = NO --&gt;
&lt;h3 id=&#34;windows-authentication-kerberos-issues&#34;&gt;Windows Authentication (Kerberos) issues&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Kerberos authentication failed&amp;rdquo; or &amp;ldquo;Cannot initialize Kerberos&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Kerberos configuration is incorrect or incomplete.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify that the Kerberos configuration file (&lt;code&gt;krb5.conf&lt;/code&gt;) path is correct in the data source settings. The default path is &lt;code&gt;/etc/krb5.conf&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For keytab authentication, ensure the keytab file exists and is readable by the Grafana service account.&lt;/li&gt;
&lt;li&gt;Check that the realm and KDC settings are correct in the Kerberos configuration.&lt;/li&gt;
&lt;li&gt;Verify DNS is correctly resolving the KDC servers.&lt;/li&gt;
&lt;li&gt;Ensure the service principal name (SPN) is registered for the SQL Server instance.&lt;/li&gt;
&lt;/ol&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;Kerberos authentication is not supported in Grafana Cloud. Use SQL Server Authentication or Azure Entra ID instead.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h3 id=&#34;kdc_err_c_principal_unknown-with-availability-group-listeners&#34;&gt;KDC_ERR_C_PRINCIPAL_UNKNOWN with Availability Group Listeners&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;KDC_ERR_C_PRINCIPAL_UNKNOWN&amp;rdquo; when connecting through a SQL Server Availability Group Listener&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The SPN registered for the SQL Server instance doesn&amp;rsquo;t match the Availability Group Listener&amp;rsquo;s DNS name. Kerberos authentication requires an SPN that matches the hostname the client connects to.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Register an SPN for the Availability Group Listener DNS name:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;text&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-text&#34;&gt;setspn -S MSSQLSvc/&amp;lt;LISTENER_FQDN&amp;gt;:1433 &amp;lt;DOMAIN&amp;gt;\&amp;lt;SERVICE_ACCOUNT&amp;gt;
setspn -S MSSQLSvc/&amp;lt;LISTENER_FQDN&amp;gt; &amp;lt;DOMAIN&amp;gt;\&amp;lt;SERVICE_ACCOUNT&amp;gt;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Verify the SPN is correctly registered: &lt;code&gt;setspn -L &amp;lt;DOMAIN&amp;gt;\&amp;lt;SERVICE_ACCOUNT&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Ensure &lt;code&gt;krb5.conf&lt;/code&gt; includes the correct realm mapping for the listener&amp;rsquo;s domain.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If using multiple realms, add cross-realm trust entries to &lt;code&gt;krb5.conf&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;untrusted-domain-errors-with-windows-authentication&#34;&gt;Untrusted domain errors with Windows Authentication&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;The login is from an untrusted domain and cannot be used with Windows authentication&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The Grafana server&amp;rsquo;s domain isn&amp;rsquo;t trusted by the SQL Server&amp;rsquo;s domain, or the Kerberos realm configuration doesn&amp;rsquo;t map correctly between domains.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Verify that a trust relationship exists between the Grafana server&amp;rsquo;s domain and the SQL Server&amp;rsquo;s domain.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Check that &lt;code&gt;krb5.conf&lt;/code&gt; includes realm mappings for both domains:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;ini&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-ini&#34;&gt;[realms]
DOMAIN_A.COM = {
  kdc = kdc1.domain_a.com
}
DOMAIN_B.COM = {
  kdc = kdc1.domain_b.com
}

[domain_realm]
.domain_a.com = DOMAIN_A.COM
.domain_b.com = DOMAIN_B.COM&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Ensure the SQL Server service account has delegation permissions if cross-domain access is needed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;As an alternative, use SQL Server Authentication or Azure Entra ID (App Registration), which don&amp;rsquo;t require domain trust.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;!-- vale Grafana.Spelling = YES --&gt;
&lt;h3 id=&#34;azure-entra-id-authentication-errors&#34;&gt;Azure Entra ID authentication errors&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;AADSTS error codes&amp;rdquo; or &amp;ldquo;Azure AD authentication failed&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Azure Entra ID (formerly Azure AD) authentication is misconfigured.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;For &lt;strong&gt;App Registration&lt;/strong&gt; authentication:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Verify the tenant ID, client ID, and client secret are correct.&lt;/li&gt;
&lt;li&gt;Ensure the app registration has been added as a user in the Azure SQL database.&lt;/li&gt;
&lt;li&gt;Check that the client secret hasn&amp;rsquo;t expired.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For &lt;strong&gt;Managed Identity&lt;/strong&gt; authentication:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Verify &lt;code&gt;managed_identity_enabled = true&lt;/code&gt; is set in the Grafana server configuration.&lt;/li&gt;
&lt;li&gt;Ensure the managed identity has been added to the Azure SQL database.&lt;/li&gt;
&lt;li&gt;Confirm the Azure resource hosting Grafana has managed identity enabled.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For &lt;strong&gt;Current User&lt;/strong&gt; authentication:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Ensure &lt;code&gt;user_identity_enabled = true&lt;/code&gt; is set in the Grafana server configuration.&lt;/li&gt;
&lt;li&gt;Verify the app registration is configured to issue both Access Tokens and ID Tokens.&lt;/li&gt;
&lt;li&gt;Check that the required API permissions are configured (&lt;code&gt;user_impersonation&lt;/code&gt; for Azure SQL).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For detailed Azure authentication configuration, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/configure/&#34;&gt;Configure the Microsoft SQL Server data source&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;query-errors&#34;&gt;Query errors&lt;/h2&gt;
&lt;p&gt;These errors occur when there are issues with query syntax or configuration.&lt;/p&gt;
&lt;h3 id=&#34;time-column-not-found-or-invalid&#34;&gt;Time column not found or invalid&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Could not find time column&amp;rdquo; or time series visualization shows no data&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The query doesn&amp;rsquo;t return a properly formatted &lt;code&gt;time&lt;/code&gt; column for time series visualization.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Ensure your query includes a column named &lt;code&gt;time&lt;/code&gt; when using the &lt;strong&gt;Time series&lt;/strong&gt; format.&lt;/li&gt;
&lt;li&gt;Use the &lt;code&gt;$__time()&lt;/code&gt; macro to rename your date column: &lt;code&gt;$__time(your_date_column)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Verify the time column is of a valid SQL date/time type (&lt;code&gt;datetime&lt;/code&gt;, &lt;code&gt;datetime2&lt;/code&gt;, &lt;code&gt;date&lt;/code&gt;) or contains Unix epoch values.&lt;/li&gt;
&lt;li&gt;Ensure the result set is sorted by the time column using &lt;code&gt;ORDER BY&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;macro-expansion-errors&#34;&gt;Macro expansion errors&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Error parsing query&amp;rdquo; or macros appear unexpanded in the query&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Grafana macros are being used incorrectly.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify macro syntax: use &lt;code&gt;$__timeFilter(column)&lt;/code&gt; not &lt;code&gt;$_timeFilter(column)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Macros don&amp;rsquo;t work inside stored procedures—use explicit date parameters instead.&lt;/li&gt;
&lt;li&gt;Check that the column name passed to macros exists in your table.&lt;/li&gt;
&lt;li&gt;View the expanded query by clicking &lt;strong&gt;Generated SQL&lt;/strong&gt; after running the query to debug macro expansion.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;timezone-and-time-shift-issues&#34;&gt;Timezone and time shift issues&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Time series data appears shifted or doesn&amp;rsquo;t align with expected times.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Store timestamps in UTC in your database to avoid timezone issues.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Time macros (&lt;code&gt;$__time&lt;/code&gt;, &lt;code&gt;$__timeFilter&lt;/code&gt;, etc.) always expand to UTC values.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If your timestamps are stored in local time, convert them to UTC in your query:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;SQL&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-sql&#34;&gt;SELECT
  your_datetime_column AT TIME ZONE &amp;#39;Your Local Timezone&amp;#39; AT TIME ZONE &amp;#39;UTC&amp;#39; AS time,
  value
FROM your_table&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Don&amp;rsquo;t pass timezone parameters to time macros—they&amp;rsquo;re not supported.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;query-returns-too-many-rows&#34;&gt;Query returns too many rows&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Result set too large&amp;rdquo; or browser becomes unresponsive&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The query returns more data than can be efficiently processed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Add time filters using &lt;code&gt;$__timeFilter(column)&lt;/code&gt; to limit data to the dashboard time range.&lt;/li&gt;
&lt;li&gt;Use aggregations (&lt;code&gt;AVG&lt;/code&gt;, &lt;code&gt;SUM&lt;/code&gt;, &lt;code&gt;COUNT&lt;/code&gt;) with &lt;code&gt;GROUP BY&lt;/code&gt; instead of returning raw rows.&lt;/li&gt;
&lt;li&gt;Add a &lt;code&gt;TOP&lt;/code&gt; clause to limit results: &lt;code&gt;SELECT TOP 1000 ...&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use the &lt;code&gt;$__timeGroup()&lt;/code&gt; macro to aggregate data into time intervals.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;stored-procedure-returns-no-data&#34;&gt;Stored procedure returns no data&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Stored procedure output isn&amp;rsquo;t being captured correctly.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Ensure the stored procedure uses &lt;code&gt;SELECT&lt;/code&gt; statements, not just variable assignments.&lt;/li&gt;
&lt;li&gt;Remove &lt;code&gt;SET NOCOUNT ON&lt;/code&gt; if present, or ensure it&amp;rsquo;s followed by a &lt;code&gt;SELECT&lt;/code&gt; statement.&lt;/li&gt;
&lt;li&gt;Verify the stored procedure parameters are being passed correctly.&lt;/li&gt;
&lt;li&gt;Test the stored procedure directly in SQL Server Management Studio with the same parameters.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For more information on using stored procedures, refer to the 
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/query-editor/&#34;&gt;query editor documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;performance-issues&#34;&gt;Performance issues&lt;/h2&gt;
&lt;p&gt;These issues relate to slow queries or high resource usage.&lt;/p&gt;
&lt;h3 id=&#34;slow-query-execution&#34;&gt;Slow query execution&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Queries take a long time to execute.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Reduce the dashboard time range to limit data volume.&lt;/li&gt;
&lt;li&gt;Add indexes to columns used in &lt;code&gt;WHERE&lt;/code&gt; clauses and time filters.&lt;/li&gt;
&lt;li&gt;Use aggregations instead of returning individual rows.&lt;/li&gt;
&lt;li&gt;Increase the &lt;strong&gt;Min time interval&lt;/strong&gt; setting to reduce the number of data points.&lt;/li&gt;
&lt;li&gt;Review the query execution plan in SQL Server Management Studio to identify bottlenecks.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;connection-pool-exhaustion&#34;&gt;Connection pool exhaustion&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Error message:&lt;/strong&gt; &amp;ldquo;Too many connections&amp;rdquo;, &amp;ldquo;Connection pool exhausted&amp;rdquo;, or &amp;ldquo;failed to connect to server&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Too many concurrent connections to the database. This commonly manifests as intermittent alert failures while dashboards continue to work, because alert evaluations and dashboard queries compete for connections from the same pool.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Increase the &lt;strong&gt;Max open&lt;/strong&gt; connection limit in the data source configuration. A value of &lt;code&gt;50&lt;/code&gt; to &lt;code&gt;100&lt;/code&gt; handles most deployments with concurrent dashboards and alerts.&lt;/li&gt;
&lt;li&gt;Enable &lt;strong&gt;Auto max idle&lt;/strong&gt; to automatically manage idle connections.&lt;/li&gt;
&lt;li&gt;Set &lt;strong&gt;Max lifetime&lt;/strong&gt; to &lt;code&gt;14400&lt;/code&gt; (4 hours) to ensure stale connections are recycled.&lt;/li&gt;
&lt;li&gt;Reduce the number of panels querying the same data source simultaneously, or split heavy dashboards into multiple pages.&lt;/li&gt;
&lt;li&gt;Check for long-running queries that might be holding connections open (review SQL Server&amp;rsquo;s &lt;code&gt;sys.dm_exec_sessions&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;If alerts fail intermittently but dashboards work, this is a strong indicator of pool exhaustion under concurrent load.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;slow-dashboard-load-with-read-only-replicas&#34;&gt;Slow dashboard load with read-only replicas&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Symptoms:&lt;/strong&gt; Dashboards take 5 to 6 minutes to load initially, or queries are significantly slower than expected.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; The data source is configured with &lt;code&gt;ApplicationIntent=ReadOnly&lt;/code&gt; in the &lt;strong&gt;Host&lt;/strong&gt; field, which routes all queries to a read-only secondary replica. If the replica is undersized, under-indexed, or experiencing replication lag, queries run much slower than on the primary.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Remove &lt;code&gt;ApplicationIntent=ReadOnly&lt;/code&gt; from the Host field to route queries back to the primary instance.&lt;/li&gt;
&lt;li&gt;If you need to use a read-only replica, ensure it has the same indexes and resources as the primary.&lt;/li&gt;
&lt;li&gt;Check the replica&amp;rsquo;s replication lag and resource utilization (CPU, I/O) during slow periods.&lt;/li&gt;
&lt;li&gt;Consider creating a separate data source for replica queries and using it only for specific dashboards that don&amp;rsquo;t require low latency.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;alert-errors&#34;&gt;Alert errors&lt;/h2&gt;
&lt;p&gt;These errors occur when using Microsoft SQL Server queries in Grafana Alerting.&lt;/p&gt;
&lt;h3 id=&#34;alerts-fail-intermittently-while-dashboards-work&#34;&gt;Alerts fail intermittently while dashboards work&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Connection pool exhaustion. Alert evaluations and dashboard queries share the same connection pool. Under concurrent load, alert evaluations may time out waiting for a free connection.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Refer to &lt;a href=&#34;#connection-pool-exhaustion&#34;&gt;Connection pool exhaustion&lt;/a&gt; in the Performance issues section above.&lt;/p&gt;
&lt;h3 id=&#34;alert-queries-return-no-data&#34;&gt;Alert queries return no data&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Alert queries have different requirements than dashboard queries.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Ensure the query format is set to &lt;strong&gt;Time series&lt;/strong&gt; (Table format isn&amp;rsquo;t supported for alerting).&lt;/li&gt;
&lt;li&gt;Verify the query doesn&amp;rsquo;t use template variables (alert queries can&amp;rsquo;t resolve dashboard variables).&lt;/li&gt;
&lt;li&gt;Check that the query returns data within the alert evaluation time range.&lt;/li&gt;
&lt;li&gt;Test the query in Explore with a fixed time range to confirm it returns results.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For more information, refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/alerting/&#34;&gt;Microsoft SQL Server alerting&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;template-variable-errors&#34;&gt;Template variable errors&lt;/h2&gt;
&lt;p&gt;These errors occur when using template variables in queries.&lt;/p&gt;
&lt;h3 id=&#34;template-variable-queries-fail&#34;&gt;Template variable queries fail&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Variable queries return unexpected results or errors.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Verify the variable query syntax is valid SQL that returns a single column.&lt;/li&gt;
&lt;li&gt;Check that the data source connection is working.&lt;/li&gt;
&lt;li&gt;Ensure the user has permission to access the tables referenced in the variable query.&lt;/li&gt;
&lt;li&gt;Test the query in the query editor before using it as a variable query.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;double-quoting-breaks-queries-with-multi-value-variables&#34;&gt;Double-quoting breaks queries with multi-value variables&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Since Grafana v11.3, multi-value variables used with &lt;code&gt;IN&lt;/code&gt; are automatically quoted. If you manually wrapped the variable in quotes (for example, &lt;code&gt;WHERE col IN (&#39;${var}&#39;)&lt;/code&gt;), values are now double-quoted (for example, &lt;code&gt;&#39;&#39;value&#39;&#39;&lt;/code&gt;), causing query failures.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Remove manual quotes around the variable: use &lt;code&gt;WHERE col IN ($var)&lt;/code&gt; instead of &lt;code&gt;WHERE col IN (&#39;${var}&#39;)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For single-value comparisons, use the &lt;code&gt;sqlstring&lt;/code&gt; format: &lt;code&gt;WHERE col = ${var:sqlstring}&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Refer to 
    &lt;a href=&#34;/docs/grafana/v13.2/datasources/mssql/template-variables/&#34;&gt;Template variables&lt;/a&gt; for formatting options.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;other-common-issues&#34;&gt;Other common issues&lt;/h2&gt;
&lt;p&gt;The following issues don&amp;rsquo;t produce specific error messages but are commonly encountered.&lt;/p&gt;
&lt;h3 id=&#34;system-databases-appear-in-queries&#34;&gt;System databases appear in queries&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Queries accidentally access system databases.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The query editor automatically excludes &lt;code&gt;tempdb&lt;/code&gt;, &lt;code&gt;model&lt;/code&gt;, &lt;code&gt;msdb&lt;/code&gt;, and &lt;code&gt;master&lt;/code&gt; from the database dropdown.&lt;/li&gt;
&lt;li&gt;Always specify the database in your data source configuration to restrict access.&lt;/li&gt;
&lt;li&gt;Ensure the database user only has permissions on the intended database.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;data-appears-incorrect-or-misaligned&#34;&gt;Data appears incorrect or misaligned&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt; Data formatting or type conversion issues.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use explicit column aliases to ensure consistent naming: &lt;code&gt;SELECT value AS metric&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Verify numeric columns are actually numeric types, not strings.&lt;/li&gt;
&lt;li&gt;Check for &lt;code&gt;NULL&lt;/code&gt; values that might affect aggregations.&lt;/li&gt;
&lt;li&gt;Use the &lt;code&gt;FILL&lt;/code&gt; option in &lt;code&gt;$__timeGroup()&lt;/code&gt; macro to handle missing data points.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;get-additional-help&#34;&gt;Get additional help&lt;/h2&gt;
&lt;p&gt;If you continue to experience issues after following this troubleshooting guide:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Check the &lt;a href=&#34;https://community.grafana.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana community forums&lt;/a&gt; for similar issues.&lt;/li&gt;
&lt;li&gt;Review the &lt;a href=&#34;https://github.com/grafana/grafana/issues&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Grafana GitHub issues&lt;/a&gt; for known bugs.&lt;/li&gt;
&lt;li&gt;Enable debug logging in Grafana to capture detailed error information.&lt;/li&gt;
&lt;li&gt;Check SQL Server logs for additional error details.&lt;/li&gt;
&lt;li&gt;Contact &lt;a href=&#34;/contact/&#34;&gt;Grafana Support&lt;/a&gt; if you&amp;rsquo;re an Enterprise or Cloud customer.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;When reporting issues, include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Grafana version&lt;/li&gt;
&lt;li&gt;SQL Server version&lt;/li&gt;
&lt;li&gt;Error messages (redact sensitive information)&lt;/li&gt;
&lt;li&gt;Steps to reproduce&lt;/li&gt;
&lt;li&gt;Relevant query examples (redact sensitive data)&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="troubleshoot-microsoft-sql-server-data-source-issues">Troubleshoot Microsoft SQL Server data source issues&lt;/h1>
&lt;p>This document provides solutions to common issues you may encounter when configuring or using the Microsoft SQL Server (MSSQL) data source in Grafana.&lt;/p></description></item></channel></rss>