This is a valid RSS feed.
This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations.
line 73, column 0: (41 occurrences) [help]
<p><img width="795" height="494" class="wp-image-4148482" src="data:image/gi ...
line 73, column 0: (41 occurrences) [help]
<p><img width="795" height="494" class="wp-image-4148482" src="data:image/gi ...
line 73, column 0: (40 occurrences) [help]
<p><img width="795" height="494" class="wp-image-4148482" src="data:image/gi ...
line 73, column 0: (40 occurrences) [help]
<p><img width="795" height="494" class="wp-image-4148482" src="data:image/gi ...
line 80, column 0: (40 occurrences) [help]
<p><img loading="lazy" width="1380" height="788" class="wp-image-4148483" sr ...
line 578, column 0: (13 occurrences) [help]
<content:encoded><![CDATA[<h2 data-start="609" data-end="630"><str ...
line 578, column 0: (13 occurrences) [help]
<content:encoded><![CDATA[<h2 data-start="609" data-end="630"><str ...
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
>
<channel>
<title>Articles - SQLServerCentral</title>
<atom:link href="https://www.sqlservercentral.com/articles/feed" rel="self" type="application/rss+xml" />
<link>https://www.sqlservercentral.com</link>
<description>The #1 SQL Server community</description>
<lastBuildDate>Mon, 28 Apr 2025 23:30:24 +0000</lastBuildDate>
<language>en-GB</language>
<sy:updatePeriod>
hourly </sy:updatePeriod>
<sy:updateFrequency>
1 </sy:updateFrequency>
<generator>https://wordpress.org/?v=6.0.3</generator>
<item>
<title>How to Load a Date Dimension in Microsoft Fabric using Macros in dbt?</title>
<link>https://www.sqlservercentral.com/articles/how-to-load-a-date-dimension-in-microsoft-fabric-using-macros-in-dbt</link>
<dc:creator><![CDATA[Additional Articles]]></dc:creator>
<pubDate>Wed, 30 Apr 2025 00:00:14 +0000</pubDate>
<category><![CDATA[Microsoft Fabric (Azure Synapse, Data Engineering, etc.)]]></category>
<guid isPermaLink="false">https://www.sqlservercentral.com/?post_type=ssc_article&p=4583665</guid>
<description><![CDATA[<p>The article A gentle introduction to dbt explains how you can get dbt in the cloud version, how you can set up a free account, and how to create a connection to a Microsoft Fabric warehouse.</p>
<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/how-to-load-a-date-dimension-in-microsoft-fabric-using-macros-in-dbt">How to Load a Date Dimension in Microsoft Fabric using Macros in dbt?</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></description>
<content:encoded><![CDATA[<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/how-to-load-a-date-dimension-in-microsoft-fabric-using-macros-in-dbt">How to Load a Date Dimension in Microsoft Fabric using Macros in dbt?</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></content:encoded>
</item>
<item>
<title>Navigating Your Test Data Challenges: Insights and Solutions</title>
<link>https://www.sqlservercentral.com/articles/navigating-your-test-data-challenges-insights-and-solutions</link>
<dc:creator><![CDATA[Press Release]]></dc:creator>
<pubDate>Mon, 07 Apr 2025 00:00:59 +0000</pubDate>
<category><![CDATA[Uncategorized]]></category>
<guid isPermaLink="false">https://www.sqlservercentral.com/?post_type=ssc_article&p=4572820</guid>
<description><![CDATA[<p>Join Redgate on May 1st for an insightful webinar cohosted with analyst firm, Bloor Research, featuring independent Senior Analyst Daniel Howard and Redgate's Steve Jones. Discover the biggest test data challenges, the latest approaches like AI synthetic data generation, and how effective test data management can benefit your entire organization. Don't miss out on this opportunity to gain valuable insights and solutions.</p>
<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/navigating-your-test-data-challenges-insights-and-solutions">Navigating Your Test Data Challenges: Insights and Solutions</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></description>
<content:encoded><![CDATA[<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/navigating-your-test-data-challenges-insights-and-solutions">Navigating Your Test Data Challenges: Insights and Solutions</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></content:encoded>
</item>
<item>
<title>How to Forecast Data in Power BI</title>
<link>https://www.sqlservercentral.com/articles/how-to-forecast-data-in-power-bi</link>
<dc:creator><![CDATA[Daniel Calbimonte]]></dc:creator>
<pubDate>Mon, 27 Feb 2023 00:00:30 +0000</pubDate>
<category><![CDATA[Power BI]]></category>
<category><![CDATA[forecast]]></category>
<guid isPermaLink="false">https://www.sqlservercentral.com/?post_type=ssc_article&p=4148481</guid>
<description><![CDATA[<p>Learn how you can use Power BI to forecase the future trends of data.</p>
<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/how-to-forecast-data-in-power-bi">How to Forecast Data in Power BI</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></description>
<content:encoded><![CDATA[<h2>Introduction</h2>
<p>In this article, we will learn how to Forecast data in Power BI. Forecasting in Power BI will help us to predict the future based on our current information. You can easily forecast in Power BI by following some simple steps.</p>
<p><img width="795" height="494" class="wp-image-4148482" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-forecast-chart.png" data-lazy-load alt="forecast data in power bi - forecast chart" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-forecast-chart.png 795w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-forecast-chart-300x186.png 300w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-forecast-chart-768x477.png 768w" sizes="(max-width: 795px) 100vw, 795px" /></p>
<h2>Requirements to forecast data in Power BI</h2>
<p>First, we need to have the <a href="https://powerbi.microsoft.com/en-us/downloads/">Power BI Desktop</a> installed.</p>
<p>Secondly, we need <a href="https://www.sqlservercentral.com/blogs/sql-server-2019-step-by-step-installation">SQL Server installed</a>.</p>
<p>Finally, we will use the<a href="https://www.sqlservercentral.com/articles/sql-server-sample-databases-2"> Adventureworks database</a>.</p>
<h2>Import data</h2>
<p>First, in Power BI press the <strong>Get data</strong> option.</p>
<p><img loading="lazy" width="1380" height="788" class="wp-image-4148483" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-get-data.jpeg" data-lazy-load alt="forecast data in power bi - get data" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-get-data.jpeg 1380w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-get-data-300x171.jpeg 300w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-get-data-1024x585.jpeg 1024w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-get-data-768x439.jpeg 768w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-get-data-128x72.jpeg 128w" sizes="(max-width: 1380px) 100vw, 1380px" /></p>
<p>Secondly, select the <strong>SQL Server database option</strong> and press <strong>Connect.</strong></p>
<p><img loading="lazy" width="600" height="660" class="wp-image-4148484" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-sql-server-source.jpeg" data-lazy-load alt="forecast data in power bi - SQL Server source" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-sql-server-source.jpeg 600w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-sql-server-source-273x300.jpeg 273w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<p>Thirdly, write the SQL Server name. In my case, I am using the local server. Press <strong>OK.</strong></p>
<p><img loading="lazy" width="701" height="335" class="wp-image-4148485" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-sql-server-connection.jpeg" data-lazy-load alt="forecast data in power bi - sql server connection properties" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-sql-server-connection.jpeg 701w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-sql-server-connection-300x143.jpeg 300w" sizes="(max-width: 701px) 100vw, 701px" /></p>
<p>Also, in the Adventureworks database, check the <strong>Purchasing.PurchaseOrderDetail</strong> table. This is a table of the purchases made by the Adventureworks company. Next, press <strong>Load.</strong></p>
<p><img loading="lazy" width="881" height="680" class="wp-image-4148486" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-preview-view-of-the-da.jpeg" data-lazy-load alt="forecast data in power bi - Preview view of the data" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-preview-view-of-the-da.jpeg 881w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-preview-view-of-the-da-300x232.jpeg 300w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-preview-view-of-the-da-768x593.jpeg 768w" sizes="(max-width: 881px) 100vw, 881px" /></p>
<h2>Visualize the data to forecast</h2>
<p>First, check the <strong>Purchasing.PurchaseOrderDetail</strong> table and the <strong>Year</strong>. Also, check the <strong>OrderQty</strong> field.</p>
<p><img loading="lazy" width="203" height="503" class="wp-image-4148487" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/select-fields.jpeg" data-lazy-load alt="Select fields" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/select-fields.jpeg 203w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/select-fields-121x300.jpeg 121w" sizes="(max-width: 203px) 100vw, 203px" /></p>
<p>Secondly, select the Line chart. Make sure that the <strong>DueDate </strong>Year in the X-axis and the Y-axis have the <strong>Sum of OrderQty</strong>.</p>
<p><img loading="lazy" width="189" height="653" class="wp-image-4148488" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/select-the-line-chart.png" data-lazy-load alt="Select the line chart" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/select-the-line-chart.png 189w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/select-the-line-chart-87x300.png 87w" sizes="(max-width: 189px) 100vw, 189px" /></p>
<p>If everything is OK, the chart will look like this:</p>
<p><img loading="lazy" width="821" height="508" class="wp-image-4148489" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-forecast-chart-created.jpeg" data-lazy-load alt="forecast data in power bi - forecast chart created" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-forecast-chart-created.jpeg 821w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-forecast-chart-created-300x186.jpeg 300w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-forecast-chart-created-768x475.jpeg 768w" sizes="(max-width: 821px) 100vw, 821px" /></p>
<p>The company started in 2011 and until 2014 the sales increased to 1,5 million. In 2013, the sales were around 692K, and in 2012 140k.</p>
<h3>Further analyses of your visual</h3>
<p>To enable the forecast option, select <strong>add further analyses to your visual</strong> icon and then turn on the <strong>Forecast</strong> option. Note that the forecast option is not available if Power BI does not detect dates in the chart. If Power BI does not detect dates in the fields used, by the chart, you will not see the forecast option.</p>
<p><img loading="lazy" width="195" height="575" class="wp-image-4148490" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-option.png" data-lazy-load alt="Forecast option" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-option.png 195w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-option-102x300.png 102w" sizes="(max-width: 195px) 100vw, 195px" /></p>
<p>The Forecast includes the following options.</p>
<ul>
<li>First, we have units. <strong>Units</strong> are used to find if we want to forecast in Years, Quarters, Days or whatever option is available for the time.</li>
<li>Secondly, we have<strong> Forecast Length. </strong>It is used to configure how many units ahead do we want to forecast. By default, the number is 10. In this example, we are using the Forecast length equal to 10, which means that we will forecast 10 years.</li>
<li>Thirdly we have the<strong> Ignore the last option</strong>. It is useful when you think that some intervals of time should not be included in the forecast analysis because they are not representative. For example, if we had great sales before the COVID pandemic and during the pandemic, we have bad years. We think our forecast should not include the last 2 years because we are optimistic.</li>
<li>Also, we have<strong> Seasonality.</strong> It is an option in Power BI. The option is used to determine some tendencies at a certain time. It will detect certain variations during the year. This option could be used to determine some patterns in the information and make some predictions about the future. For example, we can detect more sales during winter or during summer. Some valid values for seasonality are yearly, quarterly, monthly, weekly, and daily.</li>
<li>Finally, we have the <strong>Confidence interval.</strong> This is a percentage used to determine how confident the value is. It is a range of values of the forecasted value. We consider this as the forecasting value with a margin of error. This margin is set by the user.</li>
</ul>
<p><img loading="lazy" width="184" height="394" class="wp-image-4148491" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-properties-in-power-bi.jpeg" data-lazy-load alt="forecast properties in Power BI" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-properties-in-power-bi.jpeg 184w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-properties-in-power-bi-140x300.jpeg 140w" sizes="(max-width: 184px) 100vw, 184px" /></p>
<p>The current sales values from 2011-2014 are represented in a blue line. Also, the black line with a gray background represents the forecasting values. According to the forecast, our sales will reach 6 million in 2024.</p>
<p><img loading="lazy" width="796" height="482" class="wp-image-4148492" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-forecast-values.jpeg" data-lazy-load alt="forecast data in power bi - forecast values" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-forecast-values.jpeg 796w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-forecast-values-300x182.jpeg 300w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-forecast-values-768x465.jpeg 768w" sizes="(max-width: 796px) 100vw, 796px" /></p>
<h2>Upper bound and Lower bound values</h2>
<p>If you move the mouse over the lines in the chart, you will notice that the line has 3 values:</p>
<ul>
<li>First, you have the <strong>Forecast value </strong>which is the estimated value.</li>
<li>Secondly, you have the <strong>Upper bound</strong> which is the maximum forecast value.</li>
<li>Finally, you have <strong>Lower bound</strong> which is the minimum forecast value. Both, the upper bound and lower bound are determined by the Confidence interval explained previously.</li>
</ul>
<p><img loading="lazy" width="475" height="331" class="wp-image-4148493" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-upper-bound-lower-boun.jpeg" data-lazy-load alt="forecast data in power bi - upper bound lower bound" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-upper-bound-lower-boun.jpeg 475w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-data-in-power-bi-upper-bound-lower-boun-300x209.jpeg 300w" sizes="(max-width: 475px) 100vw, 475px" /></p>
<h2>Change the forecast length data in Power BI</h2>
<p>We will show how to change the number of years, and months forecasted.</p>
<p>First, in order to change the prediction from 10 years to 2 years, change the Forecast length from 10 to 2</p>
<p><img loading="lazy" width="181" height="348" class="wp-image-4148494" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-lenght.png" data-lazy-load alt="Forecast lenght" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-lenght.png 181w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-lenght-156x300.png 156w" sizes="(max-width: 181px) 100vw, 181px" /></p>
<p>Secondly, verify the chart generated. Note that the forecasting line is shorter (it represents 2 years instead of 10).</p>
<p><img loading="lazy" width="789" height="484" class="wp-image-4148495" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/chart-forecast.jpeg" data-lazy-load alt="chart forecast" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/chart-forecast.jpeg 789w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/chart-forecast-300x184.jpeg 300w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/chart-forecast-768x471.jpeg 768w" sizes="(max-width: 789px) 100vw, 789px" /></p>
<h2>Forecast data in Power BI – Changing the format</h2>
<p>Follow these steps to change the forecast format in Power BI:</p>
<p>First, press <strong>add further analyses to your visual</strong> icon.</p>
<p>Secondly, look for the Forecast line.</p>
<p><img loading="lazy" width="270" height="623" class="wp-image-4148496" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-line.png" data-lazy-load alt="Forecast line" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-line.png 270w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-line-130x300.png 130w" sizes="(max-width: 270px) 100vw, 270px" /></p>
<p>You have 3 options here:</p>
<ol>
<li>First, you have the color which is used to change the color of the forecast line.</li>
<li>Secondly, you have a style that can be dotted, solid, or dashed.</li>
<li>Finally, you can configure the transparency of the forecast colors.</li>
</ol>
<p><img loading="lazy" width="795" height="494" class="wp-image-4148497" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/format-options.jpeg" data-lazy-load alt="format options" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/format-options.jpeg 795w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/format-options-300x186.jpeg 300w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/format-options-768x477.jpeg 768w" sizes="(max-width: 795px) 100vw, 795px" /></p>
<p>In addition, you can configure the <strong>Confidence band. </strong>By default, you fill in, but you can use lines or remove the confidence band using the none option. Finally, you have the option to modify the tooltip title of the forecast value.</p>
<p><img loading="lazy" width="247" height="297" class="wp-image-4148498" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/confidence-band.png" data-lazy-load alt="Confidence band" /></p>
<h2>Forecast data in Power BI</h2>
<p>Sometimes you need to see the values instead of watching the chart only. To check a table instead of a chart, you can follow these steps:</p>
<p>First, click on the <strong>More options </strong>icon.</p>
<p>Secondly, select the <strong>Show as a table</strong> option.</p>
<p><img loading="lazy" width="908" height="503" class="wp-image-4148499" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/show-as-a-table.png" data-lazy-load alt="Show as a table " data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/show-as-a-table.png 908w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/show-as-a-table-300x166.png 300w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/show-as-a-table-768x425.png 768w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/show-as-a-table-128x72.png 128w" sizes="(max-width: 908px) 100vw, 908px" /></p>
<p>Finally, you will be able to see in a table the ForecastValue, the confidence Hight Bound and Low Bound values which were explained previously.</p>
<p><img loading="lazy" width="821" height="254" class="wp-image-4148500" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-values.png" data-lazy-load alt="forecast values" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-values.png 821w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-values-300x93.png 300w, https://www.sqlservercentral.com/wp-content/uploads/2023/02/forecast-values-768x238.png 768w" sizes="(max-width: 821px) 100vw, 821px" /></p>
<h2>Conclusion</h2>
<p>In this article, we saw how to forecast values. In our example, we predicted the order quantity values of the table purchasing.purchaseorderdetail table of the AdventureWorks database.</p>
<p>Also, we understood how to configure the forecast properties including the format options. Finally, we learned how to show the forecast values instead of the table.</p>
<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/how-to-forecast-data-in-power-bi">How to Forecast Data in Power BI</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></content:encoded>
</item>
<item>
<title>Meta AI by Facebook: A New Contender in the AI Battle</title>
<link>https://www.sqlservercentral.com/articles/meta-ai-by-facebook-a-new-contender-in-the-ai-battle</link>
<dc:creator><![CDATA[Daniel Calbimonte]]></dc:creator>
<pubDate>Mon, 28 Apr 2025 00:00:47 +0000</pubDate>
<category><![CDATA[Artificial Intelligence (AI)]]></category>
<category><![CDATA[meta ai]]></category>
<guid isPermaLink="false">https://www.sqlservercentral.com/?post_type=ssc_article&p=4559585</guid>
<description><![CDATA[<p>A short review of the Meta AI.</p>
<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/meta-ai-by-facebook-a-new-contender-in-the-ai-battle">Meta AI by Facebook: A New Contender in the AI Battle</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></description>
<content:encoded><![CDATA[<h2>Introduction</h2>
<p>Meta AI from <a href="https://www.facebook.com/">Facebook</a> is one of the last big technology giants’ contenders in the AI battle. In our first article, we created a <a href="https://www.sqlservercentral.com/articles/chatgpt-in-sql-server-practical-examples">demo about ChatGPT.</a> Secondly, we talked about <a href="https://www.sqlservercentral.com/articles/bing-chatbot-vs-chatgpt">Bing from Microsoft</a>, who is now <a href="https://www.sqlservercentral.com/articles/writing-sql-server-code-with-ai-using-github-copilot">Copilot</a>. Thirdly, we mentioned <a href="https://www.sqlservercentral.com/articles/bard-googles-chatgpt-competitor">Bard from Google,</a> which is <a href="https://www.sqlservercentral.com/articles/meet-the-new-google-ai-assistant-gemini">Gemini</a> now.</p>
<p>However, Mark Zuckerberg and Facebook did not want to be out of the AI party. Now we have <a href="https://www.meta.ai/">Meta AI</a> incorporated into WhatsApp or in Facebook. We can also use Meta AI in the browser. In this article, we will talk about this new technology.</p>
<h2>Meta AI history</h2>
<p>Meta AI was created by the Facebook Artificial Intelligence Research (FAIR). This is the division of Meta Platforms (Facebook) in charge of the artificial intelligence research. In addition, Meta AI was founded on December 11, 2015 as Facebook Artificial Intelligence Research (FAIR). FAIR started with machine learning and artificial intelligence to understand intelligence and make machines significantly more intelligent. After that, they worked on face recognition, tagging in photographs, and personalized feed recommendations. In October 2021, Facebook rebranded itself as Meta Platforms, and focused on the "metaverse" and virtual reality environments.</p>
<p>Currently, Meta is presenting the Meta AI to compete with ChatGPT, Gemini, Copilot, Deepseek, and other competitors.</p>
<h2>Getting Started</h2>
<p>Let’s start with a conversation with Meta AI.</p>
<p><strong>Daniel: Hello. What are you?</strong></p>
<p><strong>Meta AI:</strong> Hello! I'm Meta AI, a friendly AI assistant. I can help answer questions, provide information, generate text, and even create images. I'm constantly learning and improving, so please bear with me if I make any mistakes. How can I assist you today?</p>
<p><strong>Daniel: Are you based in ChatGPT or are you a completely different technology?</strong></p>
<p>We are both chatbots, but I was created by Meta, while ChatGPT was developed by OpenAI. Our training data, language understanding, and overall tone and purpose are unique, so we each have different strengths and capabilities.</p>
<h2>Can Meta AI have access to the internet?</h2>
<p><strong>Daniel: Can you navigate on the internet to get current data?</strong></p>
<p><strong>Meta AI: </strong>I can't browse the internet or access real-time data. My responses are based on the data I was trained on, which is a massive dataset that was available to me when I was trained. However, my training data only goes up until 2022-2023, so I may not have the most up-to-date information on very recent events or developments.</p>
<p><strong>Daniel: What are your strengths compared with Copilot and ChatGPT?</strong></p>
<p><strong>Meta AI:</strong></p>
<p>We all share some similarities, but I've been designed to be more conversational, concise, and helpful in a broader range of tasks and topics. Here are some of my strengths:</p>
<ol>
<li><strong>Conversational dialogue</strong>: I'm trained to engage in natural-sounding conversations, using a more casual tone and including relevant questions to clarify context.</li>
<li><strong>Concise responses</strong>: I aim to provide clear and direct answers, focusing on the most important information and avoiding unnecessary elaboration.</li>
<li><strong>Task-oriented</strong>: I can assist with a wide range of tasks, from generating creative content and providing definitions to solving math problems and translating languages.</li>
<li><strong>Knowledge base</strong>: While not exhaustive, my training data covers a vast range of topics, including but not limited to history, science, entertainment, culture, geography, and more.</li>
<li><strong>Multilingual support</strong>: I can understand and respond in multiple languages, making me more accessible to users worldwide.</li>
<li><strong>Continuous learning</strong>: My training data is constantly updated and expanded to keep my knowledge up-to-date and accurate.</li>
</ol>
<p>Keep in mind that each AI model has its unique strengths and weaknesses. If you have specific needs or preferences, you may find that one model works better for you than others.</p>
<h2>Meta AI opinion about SQL Server 2022</h2>
<p><strong>Daniel: What is your opinion about SQL Server 2022?</strong></p>
<p><strong>Meta AI:</strong> SQL Server 2022 is a powerful relational database management system (RDBMS) that offers numerous enhancements and improvements over its predecessors. Here are some key features and benefits:</p>
<h2>Key Features</h2>
<ol>
<li><strong>Improved Performance</strong>: SQL Server 2022 introduces several performance enhancements, including improved query optimization, faster data processing, and better resource utilization.</li>
<li><strong>Enhanced Security</strong>: The new version includes advanced security features, such as Azure Active Directory (AAD) authentication, encryption, and access control.</li>
<li><strong>Data Virtualization</strong>: SQL Server 2022 allows you to integrate data from various sources, including Azure Blob Storage, Azure Data Lake Storage, and other databases.</li>
<li><strong>Cloud-Native Capabilities</strong>: The database engine is designed to work seamlessly with cloud environments, providing features like elastic scaling, automated patching, and backup.</li>
<li><strong>Improved Analytics</strong>: SQL Server 2022 includes advanced analytics capabilities, including machine learning, data warehousing, and business intelligence.</li>
</ol>
<h2>Benefits</h2>
<ol>
<li><strong>Faster Insights</strong>: With improved performance and analytics capabilities, you can gain faster insights from your data.</li>
<li><strong>Enhanced Collaboration</strong>: SQL Server 2022 enables seamless collaboration between developers, data scientists, and business users.</li>
<li><strong>Increased Agility</strong>: The database engine provides a flexible and scalable platform for developing and deploying applications.</li>
<li><strong>Better Data Governance</strong>: With advanced security and access control features, you can ensure that your data is secure and compliant with regulatory requirements.</li>
</ol>
<p>Overall, SQL Server 2022 is a robust and feature-rich database management system that can help organizations unlock insights, improve collaboration, and drive business success.</p>
<p>Do you believe that SQL Server on premises will stop and everything will migrate to the cloud?</p>
<p>While cloud adoption is increasingly popular, I don't think SQL Server on-premises will completely disappear. Here's why:</p>
<h2>Reasons for On-Premises Persistence</h2>
<ol>
<li><strong>Data Sovereignty</strong>: Some organizations, especially those in regulated industries, require strict control over their data and may not be comfortable hosting it in the cloud.</li>
<li><strong>Security Concerns</strong>: On-premises environments can provide an additional layer of security, as data is stored within the organization's own infrastructure.</li>
<li><strong>Legacy Systems</strong>: Many organizations have invested heavily in on-premises infrastructure and may not be able to migrate their legacy systems to the cloud easily.</li>
<li><strong>Low Latency Requirements</strong>: Certain applications, such as real-time analytics or high-frequency trading, require ultra-low latency, which may be difficult to achieve in a cloud environment.</li>
</ol>
<h2>Hybrid Approach</h2>
<ol>
<li><strong>Cloud-First Strategy</strong>: Many organizations are adopting a cloud-first strategy, where new applications and workloads are deployed in the cloud, while existing on-premises workloads are maintained.</li>
<li><strong>Hybrid Cloud</strong>: Some organizations are using a hybrid cloud approach, where they use a combination of on-premises and cloud infrastructure to meet their needs.</li>
</ol>
<h2>Microsoft's Strategy</h2>
<p>Microsoft has stated that they will continue to support and invest in SQL Server on-premises, while also providing a clear path for customers to migrate to the cloud when they're ready.</p>
<p>In summary, while the cloud will continue to grow in popularity, I don't think SQL Server on-premises will completely disappear. Instead, organizations will adopt a hybrid approach, using a combination of on-premises and cloud infrastructure to meet their needs.</p>
<h2>Create some T-SQL Code with Meta AI</h2>
<p><strong>Me:</strong> It is not bad, let’s take a look at the code created. Also, can you generate some T-SQL tables with data? Please apply best practices. Based on the tables, create a view and a stored procedure.</p>
<p><strong>Meta AI: </strong>Here's an example of T-SQL tables with data, a view, and a stored procedure, following best practices:</p>
<h2>Tables</h2>
<p>SQL</p>
<pre class="prettyprint lang-mssql">-- Create schema
CREATE SCHEMA Sales
GO
-- Create tables
CREATE TABLE Sales.Customers (
CustomerId INT PRIMARY KEY IDENTITY(1,1),
FirstName NVARCHAR(50) NOT NULL,
LastName NVARCHAR(50) NOT NULL,
Email NVARCHAR(100) UNIQUE NOT NULL,
CreatedDate DATETIME DEFAULT GETDATE()
);
CREATE TABLE Sales.Orders (
OrderId INT PRIMARY KEY IDENTITY(1,1),
CustomerId INT NOT NULL,
OrderDate DATETIME DEFAULT GETDATE(),
Total DECIMAL(10, 2) NOT NULL,
CONSTRAINT FK_Orders_Customers FOREIGN KEY (CustomerId) REFERENCES Sales.Customers(CustomerId)
);
CREATE TABLE Sales.OrderItems (
OrderItemId INT PRIMARY KEY IDENTITY(1,1),
OrderId INT NOT NULL,
ProductName NVARCHAR(100) NOT NULL,
Quantity INT NOT NULL,
UnitPrice DECIMAL(10, 2) NOT NULL,
CONSTRAINT FK_OrderItems_Orders FOREIGN KEY (OrderId) REFERENCES Sales.Orders(OrderId)
);</pre>
<h2>Data</h2>
<p>SQL</p>
<pre class="prettyprint lang-mssql">-- Insert data
INSERT INTO Sales.Customers (FirstName, LastName, Email)
VALUES
('John', 'Doe', 'john.doe@example.com'),
('Jane', 'Doe', 'jane.doe@example.com'),
('Bob', 'Smith', 'bob.smith@example.com');
INSERT INTO Sales.Orders (CustomerId, Total)
VALUES
(1, 100.00),
(1, 200.00),
(2, 50.00),
(3, 75.00);
INSERT INTO Sales.OrderItems (OrderId, ProductName, Quantity, UnitPrice)
VALUES
(1, 'Product A', 2, 25.00),
(1, 'Product B', 1, 50.00),
(2, 'Product C', 3, 33.33),
(3, 'Product D', 1, 50.00),
(4, 'Product E', 2, 18.75);</pre>
<h2>View:</h2>
<p>SQL</p>
<pre class="prettyprint lang-mssql">-- Create view
CREATE VIEW Sales.CustomerOrders
AS
SELECT
C.CustomerId,
C.FirstName,
C.LastName,
O.OrderId,
O.OrderDate,
O.Total
FROM
Sales.Customers C
INNER JOIN
Sales.Orders O ON C.CustomerId = O.CustomerId;</pre>
<h2>Stored Procedure:</h2>
<p>SQL</p>
<pre class="prettyprint lang-mssql">-- Create stored procedure
CREATE PROCEDURE Sales.GetCustomerOrders
@CustomerId INT
AS
BEGIN
SELECT
O.OrderId,
O.OrderDate,
O.Total
FROM
Sales.Orders O
WHERE
O.CustomerId = @CustomerId
ORDER BY
O.OrderDate DESC;
END;
GO</pre>
<p>To execute the stored procedure:</p>
<p>SQL</p>
<pre class="prettyprint lang-mssql">EXEC Sales.GetCustomerOrders @CustomerId = 1;</pre>
<p><strong>Me: </strong>I tested the code. Also, I created the objects and tested the data. The code worked fine.</p>
<h2>Meta AI in WhatsApp</h2>
<p>Now, you can talk to Meta AI using your WhatsApp. Also, you can use the search option to ask Meta AI or press the Meta AI icon to use this service:</p>
<p><img loading="lazy" width="757" height="1600" class="wp-image-4559586" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/03/meta-ai-options-1.png" data-lazy-load alt="Meta AI options" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/03/meta-ai-options-1.png 757w, https://www.sqlservercentral.com/wp-content/uploads/2025/03/meta-ai-options-1-142x300.png 142w, https://www.sqlservercentral.com/wp-content/uploads/2025/03/meta-ai-options-1-484x1024.png 484w, https://www.sqlservercentral.com/wp-content/uploads/2025/03/meta-ai-options-1-727x1536.png 727w" sizes="(max-width: 757px) 100vw, 757px" /></p>
<p>It works in the same way.</p>
<p><strong>Daniel:</strong> Also, create a T-SQL query to detect the space used by a database.</p>
<p><strong>Meta AI: </strong>Here is a T-SQL query that detects the space used by a database:</p>
<pre class="prettyprint lang-mssql">SELECT
db.name AS DatabaseName,
CAST((SUM(file_size) * 8192.0) / 1048576.0 AS DECIMAL(10, 2)) AS TotalSpaceUsedMB
FROM
sys.master_files file
INNER JOIN
sys.databases db ON file.database_id = db.database_id
WHERE
db.name = 'YourDatabaseName'
GROUP BY
db.name</pre>
<p>Replace 'YourDatabaseName' with the name of the database you want to check.</p>
<p>This query works by:</p>
<p>1. Joining the sys.master_files and sys.databases system views to get the file size and database name.</p>
<p>2. Filtering the results to the specified database.</p>
<p>3. Grouping the results by database name.</p>
<p>4. Calculating the total space used in megabytes (MB).</p>
<p>Note: The file_size column in sys.master_files is in units of 8192 bytes (8KB), so we multiply by 8192.0 and then divide by 1048576.0 to convert to megabytes.Drawing with Meta AI</p>
<p>Also, you can create images with Meta AI in your WhatsApp or browser. However, depending on your country, this feature may be restricted.</p>
<h2>Drawing in Meta AI</h2>
<p><strong>Me: Please draw a corrupted database.</strong></p>
<p><strong>Meta AI:</strong></p>
<p><img loading="lazy" width="1280" height="1280" class="wp-image-4559587" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/03/corrupt-database-1.jpeg" data-lazy-load alt="corrupt database" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/03/corrupt-database-1.jpeg 1280w, https://www.sqlservercentral.com/wp-content/uploads/2025/03/corrupt-database-1-300x300.jpeg 300w, https://www.sqlservercentral.com/wp-content/uploads/2025/03/corrupt-database-1-1024x1024.jpeg 1024w, https://www.sqlservercentral.com/wp-content/uploads/2025/03/corrupt-database-1-150x150.jpeg 150w, https://www.sqlservercentral.com/wp-content/uploads/2025/03/corrupt-database-1-768x768.jpeg 768w" sizes="(max-width: 1280px) 100vw, 1280px" /></p>
<p><strong>Me:</strong> Mmmm…Can you generate a video of a database flying?</p>
<p><strong>Meta ai:</strong></p>
<p><img loading="lazy" width="1280" height="1280" class="wp-image-4559588" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/03/database-flying-1.jpeg" data-lazy-load alt="Database flying" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/03/database-flying-1.jpeg 1280w, https://www.sqlservercentral.com/wp-content/uploads/2025/03/database-flying-1-300x300.jpeg 300w, https://www.sqlservercentral.com/wp-content/uploads/2025/03/database-flying-1-1024x1024.jpeg 1024w, https://www.sqlservercentral.com/wp-content/uploads/2025/03/database-flying-1-150x150.jpeg 150w, https://www.sqlservercentral.com/wp-content/uploads/2025/03/database-flying-1-768x768.jpeg 768w" sizes="(max-width: 1280px) 100vw, 1280px" /></p>
<p>Daniel: It just created an image. It does not look like a database.</p>
<h2>Conclusion</h2>
<p>To conclude we can say that meta AI is currently similar to the competitors. However, if it is fully integrated to Facebook, Instagram, and WhatsApp, it will be really useful for our daily tasks.</p>
<p>Also, it will be a great assistant in the long run if it can understand our voice and do some tasks automatically.</p>
<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/meta-ai-by-facebook-a-new-contender-in-the-ai-battle">Meta AI by Facebook: A New Contender in the AI Battle</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></content:encoded>
</item>
<item>
<title>Using try catch in SQL Server stored procedures</title>
<link>https://www.sqlservercentral.com/articles/using-try-catch-in-sql-server-stored-procedures</link>
<dc:creator><![CDATA[Additional Articles]]></dc:creator>
<pubDate>Mon, 28 Apr 2025 00:00:39 +0000</pubDate>
<category><![CDATA[Error Handling]]></category>
<category><![CDATA[TRY..CATCH]]></category>
<guid isPermaLink="false">https://www.sqlservercentral.com/?post_type=ssc_article&p=4583651</guid>
<description><![CDATA[<p>A great new option that has been around since SQL Server 2005 is the ability to use the Try..Catch paradigm that exists in other development languages. Doing error handling in SQL Server has not always been the easiest thing, so this option definitely makes it much easier to code for and handle errors.</p>
<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/using-try-catch-in-sql-server-stored-procedures">Using try catch in SQL Server stored procedures</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></description>
<content:encoded><![CDATA[<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/using-try-catch-in-sql-server-stored-procedures">Using try catch in SQL Server stored procedures</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></content:encoded>
</item>
<item>
<title>Retrieving Data Using the REST API in Data API Builder</title>
<link>https://www.sqlservercentral.com/articles/retrieving-data-using-the-rest-api-in-data-api-builder</link>
<dc:creator><![CDATA[Steve Jones - SSC Editor]]></dc:creator>
<pubDate>Fri, 25 Apr 2025 00:00:11 +0000</pubDate>
<category><![CDATA[Data API Builder (DAB)]]></category>
<guid isPermaLink="false">https://www.sqlservercentral.com/?post_type=ssc_article&p=4583128</guid>
<description><![CDATA[<p>I wrote a piece on getting started with the Data API Builder (DAB), which looked at how this product works and how to start using it. That was a basic look, but it gives data professionals an idea of how this might help them work more closely with front-end developers who are more comfortable with […]</p>
<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/retrieving-data-using-the-rest-api-in-data-api-builder">Retrieving Data Using the REST API in Data API Builder</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></description>
<content:encoded><![CDATA[<p>I wrote a piece on getting started with the Data API Builder (DAB), which looked at how this product works and how to start using it. That was a basic look, but it gives data professionals an idea of how this might help them work more closely with front-end developers who are more comfortable with API access to data and dislike SQL. In this article, I want to continue to dive into DAB with a more detailed look at the REST API and how one might perform queries against the tables you have exposed from your database.</p>
<p>Note that the REST API is lightly documented at MS Learn: <a href="https://learn.microsoft.com/en-us/azure/data-api-builder/rest?tabs=http">https://learn.microsoft.com/en-us/azure/data-api-builder/rest?tabs=http</a></p>
<h2>Pre-requisites</h2>
<p>I will assume you know how to</p>
<ul>
<li>create a DAB configuration file and add entities to the file.</li>
<li>start the DAB process and find the REST API base URL</li>
<li>configure this for SQL Server</li>
<li>have <a href="https://www.postman.com/">Postman</a> installed (not required, but nice)</li>
</ul>
<p>It should be the same for other platforms, though I haven't tested those. I will also be showing examples in Postman as it makes rendering results easier. You can do this from a web browser, but it's harder to read results (and more annoying to me), or you can use any other method you want that supports accessing an http endpoint and rendering JSON results.</p>
<h2>The REST API</h2>
<p>If you are a data professional, you might not be familiar with REST APIs. These are a common way of accessing data resources, or changing them, in much of software development. These are often http URL addressed resources, with the API being a structured view over the underlying resources. You can read more about REST from <a href="https://www.redhat.com/en/topics/api/what-is-a-rest-api">Red Hat</a> or <a href="https://aws.amazon.com/what-is/restful-api/">AWS</a>, but it's not required. Essentially for us data professionals, we are exposing our database objects through an HTTP endpoint.</p>
<p>As an example, I have DAB running against the Northwind database and the Customers table exposed. The base URL for my DAB endpoint is: http://localhost:5000/api. However, this doesn't provide my anything but an error:</p>
<p><img loading="lazy" class="alignnone size-full wp-image-4583158" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0142.png" data-lazy-load alt="REST error" width="813" height="167" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0142.png 813w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0142-300x62.png 300w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0142-768x158.png 768w" sizes="(max-width: 813px) 100vw, 813px" /></p>
<p>This is because there isn't any data to return. Instead, in my config file, I have added the dbo.Customers table, and it is accessible as http://localhost:5000/api/Customers. Note all the results below, which are hard to read.</p>
<p><img loading="lazy" class="alignnone size-full wp-image-4583159" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0143.png" data-lazy-load alt="DAB returning customers" width="809" height="370" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0143.png 809w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0143-300x137.png 300w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0143-768x351.png 768w" sizes="(max-width: 809px) 100vw, 809px" /></p>
<p>This is a JSON document, with lots of elements, arrays, and more. If you are familiar with Northwind, this data looks familiar, but it's hard to consume. In .NET, there are plenty of easy ways to de-serialize this data into a series of rows and columns that could populate a table or a grid or anything the developer wants to fill with data.</p>
<p>That's a simple look at the REST API, now, let's look at what we can do with it.</p>
<p>Note, in the rest of the article I'll be using Postman to submit the URL and get results back.</p>
<h2>Selecting Certain Columns</h2>
<p>In the example above, for the base URL for Customers, I get all customers from the table, both all rows and all columns. This is essentially a SELECT * with no WHERE clause. Not what we want most developers to do from their applications.</p>
<p>Instead, we would like them to be selective about what is returned. Choose certain columns of data. I'll start to limit data in this section by only picking some columns. In the next section, we will add the filtering of a WHERE clause.</p>
<p>The REST API in DAB includes a <a href="https://learn.microsoft.com/en-us/azure/data-api-builder/rest?tabs=http#select">$select parameter</a>, which can be used as the column list to be returned. The basic syntax is:</p>
<p>/api/entity?$select=column1,column2,column3</p>
<p>Here we give the entity name, use a ? to indicate parameters are coming and then use $select as the parameter. For my Customers table, I construct a URL like this to get the CustomerID and Company Name: http://localhost:5000/api/Customers?$select=CustomerID,CompanyName</p>
<p>When I run this, I see this data. Note that Postman gives me a table in which I can edit parameters below the URL. All customers are shown in the results, but only those two columns.</p>
<p><img loading="lazy" class="alignnone size-full wp-image-4583162" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0144.png" data-lazy-load alt="Getting All Customers with jsut the ID and name" width="725" height="564" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0144.png 725w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0144-300x233.png 300w" sizes="(max-width: 725px) 100vw, 725px" /></p>
<p>If I wanted another column, like ContactName, I add it to my URL. The call is now:</p>
<pre class="prettyprint lang-plain">http://localhost:5000/api/Customers?$select=CustomerID,CompanyName,ContactName</pre>
<p>Here are the results:</p>
<p><img loading="lazy" class="alignnone size-full wp-image-4583163" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0145.png" data-lazy-load alt="resutlts with id, name, and contact" width="871" height="814" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0145.png 871w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0145-300x280.png 300w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0145-768x718.png 768w" sizes="(max-width: 871px) 100vw, 871px" /></p>
<p>One caveat here is that DAB is case sensitive in the REST API. Your casing must match what's in the DB. Here is a query in SSMS that works. Note that I've lowercased the ContactName field:</p>
<p><img loading="lazy" class="alignnone size-full wp-image-4583165" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0147.png" data-lazy-load alt="Query with mixed case in code" width="519" height="424" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0147.png 519w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0147-300x245.png 300w" sizes="(max-width: 519px) 100vw, 519px" /></p>
<p>In the REST API, the equivalent query is:</p>
<pre class="prettyprint lang-plain">http://localhost:5000/api/Customers?$select=CustomerID,CompanyName,contactname</pre>
<p>This, however, returns an error:</p>
<p><img loading="lazy" class="alignnone size-full wp-image-4583166" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0148.png" data-lazy-load alt="Error in REST API from wrong case" width="753" height="490" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0148.png 753w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0148-300x195.png 300w" sizes="(max-width: 753px) 100vw, 753px" /></p>
<p>I haven't tested how many columns can be added, but I assume there isn't a limit in DAB. I've added many, and they seem to work.</p>
<p><img loading="lazy" class="alignnone size-full wp-image-4583167" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0149.png" data-lazy-load alt="Getting Many Columns" width="1018" height="665" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0149.png 1018w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0149-300x196.png 300w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0149-768x502.png 768w" sizes="(max-width: 1018px) 100vw, 1018px" /></p>
<p>I can also rearrange the columns. In this URL, I've changed the order of columns, and I've duplicated one column:</p>
<pre class="prettyprint lang-plain">http://localhost:5000/api/Customers?$select=CompanyName,ContactTitle,ContactName,Country,CustomerID,ContactName,ContactTitle,Address,City,Region,Country</pre>
<p>In the results, however, I don't see duplicate data. DAB has removed the duplicate.</p>
<p><img loading="lazy" class="alignnone size-full wp-image-4583168" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0150.png" data-lazy-load alt="Query results with reordered columns and duplicate" width="1183" height="727" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0150.png 1183w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0150-300x184.png 300w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0150-1024x629.png 1024w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0150-768x472.png 768w" sizes="(max-width: 1183px) 100vw, 1183px" /></p>
<p>Behind the scenes, this is an sp_executesql query that looks like this (I've cleaned this up slightly to make it easier to read):</p>
<pre class="prettyprint lang-mssql">exec sp_executesql N'
SELECT TOP 101
[dbo_customers].[CompanyName] AS [CompanyName]
, [dbo_customers].[ContactTitle] AS [ContactTitle]
, [dbo_customers].[ContactName] AS [ContactName]
, [dbo_customers].[Country] AS [Country]
, [dbo_customers].[CustomerID] AS [CustomerID]
, [dbo_customers].[Address] AS [Address]
, [dbo_customers].[City] AS [City]
, [dbo_customers].[Region] AS [Region]
FROM [dbo].[customers] AS [dbo_customers]
WHERE 1 = 1
ORDER BY [dbo_customers].[CustomerID] ASC FOR JSON PATH, INCLUDE_NULL_VALUES
',N'@param0 nvarchar(11),@param1 nvarchar(12),@param2 nvarchar(11),@param3 nvarchar(7),@param4 nvarchar(10),@param5 nvarchar(7),@param6 nvarchar(4),@param7 nvarchar(6)',@param0=N'CompanyName',@param1=N'ContactTitle',@param2=N'ContactName',@param3=N'Country',@param4=N'CustomerID',@param5=N'Address',@param6=N'City',@param7=N'Region'
</pre>
<p>Note that the column list doesn't include the duplicate column.</p>
<p>It's great we can reorder which columns appear, but often we don't want all rows. Let's look at filtering next.</p>
<h2>Filtering API Results</h2>
<p>The WHERE clause is a filter for our queries. In the REST API, we use the <a href="https://learn.microsoft.com/en-us/azure/data-api-builder/rest?tabs=http#filter">$filter parameter</a>. Like $select, this will allow us to add values to limit results. However, unlike $select, this is an expression, and the format is this:</p>
<p>/api/entity?$filter=column [operator] value</p>
<p>That's the basic structure. The operators are:</p>
<ul>
<li>eq - equal</li>
<li>ne - not equal</li>
<li>gt - greater than</li>
<li>lt - less than</li>
<li>ge - greater than or equal</li>
<li>le - less than or equal</li>
</ul>
<p>The value can be a number. If it is a string, enclose it in single quotes. For dates, I'll show that below. One thing to note, for a dev, they need to URLEncode their $filter parameters.</p>
<p>Here are a couple examples to illustrate how this works. First, let's only get one customer. We can do this with a URL that uses the eq operator and the CustomerID column. The URL would be:</p>
<pre class="prettyprint lang-plain">http://localhost:5000/api/Customers?$filter=CustomerID eq 'ALFKI'</pre>
<p>This returns just this customer:</p>
<p><img loading="lazy" class="alignnone size-full wp-image-4583170" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0151.png" data-lazy-load alt="Return one customer" width="1024" height="652" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0151.png 1024w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0151-300x191.png 300w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0151-768x489.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></p>
<p>Every column in dbo.Customers is a string field, so let me switch to dbo.Orders for the next example. If I want just one particular order, I can use the order ID. My URL would be:</p>
<pre class="prettyprint lang-plain"> http://localhost:5000/api/Orders?$filter=OrderID eq 10253</pre>
<p>Note I have spaces in my expression and URL and it works. Look at my results:</p>
<p><img loading="lazy" class="alignnone size-full wp-image-4583175" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0152.png" data-lazy-load alt="Retrieve one order" width="858" height="821" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0152.png 858w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0152-300x287.png 300w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0152-768x735.png 768w" sizes="(max-width: 858px) 100vw, 858px" /></p>
<p>For a date range, I have a slightly different format. I can't use quotes or the OData style (datetime'yyyy-mm-dd'). Instead, I need to use a datetime offset value. I can still use a gt or ge expression. For example, dates for orders in Northwind range from 1996-07-04 to 1998-05-06. Let's get just the 1998 orders with this URL:</p>
<pre class="prettyprint lang-plain">http://localhost:5000/api/Orders?$filter=OrderDate ge 1998-01-01T00:00:00Z</pre>
<p>The results are here:</p>
<p><img loading="lazy" class="alignnone size-full wp-image-4583176" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0154.png" data-lazy-load alt="date filtering to 1998" width="667" height="889" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0154.png 667w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0154-225x300.png 225w" sizes="(max-width: 667px) 100vw, 667px" /></p>
<p>I can also combine multiple expressions with AND/OR/NOT, as I would in a WHERE Clause. I can also use parenthesis to group my logical expressions. In the examples below, I'm going to limit what I return and combine a few logical filters. First, let's get a limited set of data from orders that were shipped to France. The URL for this is:</p>
<pre class="prettyprint lang-plain">http://localhost:5000/api/Orders?$filter=ShipCountry eq 'France'&$select=CustomerID,OrderID,ShipCountry,OrderDate</pre>
<p>I now see just the date, customer, order, and country.</p>
<p><img loading="lazy" class="alignnone size-full wp-image-4583177" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0155.png" data-lazy-load alt="French Orders" width="1011" height="854" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0155.png 1011w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0155-300x253.png 300w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0155-768x649.png 768w" sizes="(max-width: 1011px) 100vw, 1011px" /></p>
<p>That's still 77 orders. Let's further limit this to just those orders with a number > 11000. I do that by adding values to the URL. Now I query with:</p>
<pre class="prettyprint lang-mssql">http://localhost:5000/api/Orders?$filter=ShipCountry eq 'France' and OrderID gt 11000&$select=CustomerID,OrderID,ShipCountry,OrderDate</pre>
<p>I get three results.</p>
<p><img loading="lazy" class="alignnone size-full wp-image-4583178" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0156.png" data-lazy-load alt="Orders > 11000" width="1084" height="870" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0156.png 1084w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0156-300x241.png 300w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0156-1024x822.png 1024w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0156-768x616.png 768w" sizes="(max-width: 1084px) 100vw, 1084px" /></p>
<p>Perhaps I also want to include a few orders from a different customer. Let's group our previous query and add an OR filter. This gives us a URL of:</p>
<pre class="prettyprint lang-mssql">http://localhost:5000/api/Orders?$filter=(ShipCountry eq 'France' and OrderID gt 11000) or CustomerID eq 'VINET'&$select=CustomerID,OrderID,ShipCountry,OrderDate</pre>
<p>Now I get five more rows. There are 5 VINET orders, and you can see the last one with the 3 orders from the previous query.</p>
<p><img loading="lazy" class="alignnone size-full wp-image-4583181" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0158.png" data-lazy-load alt="Complex filtering" width="1149" height="905" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0158.png 1149w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0158-300x236.png 300w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0158-1024x807.png 1024w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0158-768x605.png 768w" sizes="(max-width: 1149px) 100vw, 1149px" /></p>
<p>Just as you can in SQL, you can build up some expressions here. I don't know the limits of DAB, but I would also expect these not to be too complex as this is designed to replace relatively basic CRUD operations from an application.</p>
<p>We have looked at limiting results in a few ways, but what about ordering? Clients can order results, and if the set is small the should, but there is power in letting the server do some of this work. Let's look at adding an ORDER BY clause.</p>
<h2>Ordering Results</h2>
<p>My previous results were in whatever order the server wanted to return them to me. However, if I wanted to ensure a certain order, there is an <a href="https://learn.microsoft.com/en-us/azure/data-api-builder/rest?tabs=http#orderby">$orderby parameter</a> in DAB. As you might expect, this equates to the ORDER BY keywords in T-SQL, and you can add a list of columns (case-sensitive). The structure is</p>
<p>/api/entity?$orderby=column1,column2</p>
<p>For my last query, I have a complex expression, but let's now order all the results by the employee that took the order. To do that, I add a new parameter and then the $orderby keyword. That give me this URL:</p>
<pre class="prettyprint lang-mssql">http://localhost:5000/api/Orders?$filter=(ShipCountry eq 'France' and OrderID gt 11000) or CustomerID eq 'VINET'&$select=CustomerID,OrderID,ShipCountry,OrderDate&$orderby=EmployeeID</pre>
<p>My results show the VINET orders mixed in with the others that are limited by country and date. I've ordered by a column I'm not retrieving, just as I can in T-SQL.</p>
<p><img loading="lazy" class="alignnone size-full wp-image-4583182" src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0159.png" data-lazy-load alt="Ordered Results" width="1279" height="862" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0159.png 1279w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0159-300x202.png 300w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0159-1024x690.png 1024w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/2025-04_0159-768x518.png 768w" sizes="(max-width: 1279px) 100vw, 1279px" /></p>
<p>I can add multiple columns, but I'm sure you understand how to use this parameter.</p>
<h2>Summary</h2>
<p>There are a few more things you can do with DAB to retrieve data, but I'll cover those in another article. In this one, we've seen how to limit the columns returned, the rows, and to order them. These equate to a column list, a WHERE clause, and an ORDER BY clause in T-SQL. Most developers likely understand these concepts well, and the only strange thing might be encoding dates with the datetimeoffset value for the parameter when used in expressions.</p>
<p>DAB is a way to speed up front-end development, and a way that helps DBAs control what they expose to developers. This can be a nice front end for the database, limiting what data certain applications can access without adding any complex RBAC rules with GRANT and REVOKE statements in the database. Of course, users do need to be granted permissions, but this is one further way to keep your security simple and help developers access data in a way that they are comfortable with working.</p>
<p>Give it a try today and experiment with the Data API Builder. It can speed up a lot of front end drudgery with those simple CRUD applications.</p>
<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/retrieving-data-using-the-rest-api-in-data-api-builder">Retrieving Data Using the REST API in Data API Builder</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></content:encoded>
</item>
<item>
<title>Managed Instance Gotchas – Error Conditions</title>
<link>https://www.sqlservercentral.com/articles/managed-instance-gotchas-error-conditions</link>
<dc:creator><![CDATA[Additional Articles]]></dc:creator>
<pubDate>Fri, 25 Apr 2025 00:00:31 +0000</pubDate>
<category><![CDATA[Azure SQL Managed Instance]]></category>
<guid isPermaLink="false">https://www.sqlservercentral.com/?post_type=ssc_article&p=4575514</guid>
<description><![CDATA[<p>I was recently on a project to migrate a very transactional installation of SQL Server to Azure SQL Managed Instance (MI). SQL Managed Instance is a good stepping stone between a full, on-prem SQL instance / Azure VM and an Azure SQL Database. </p>
<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/managed-instance-gotchas-error-conditions">Managed Instance Gotchas – Error Conditions</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></description>
<content:encoded><![CDATA[<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/managed-instance-gotchas-error-conditions">Managed Instance Gotchas – Error Conditions</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></content:encoded>
</item>
<item>
<title>Using the CASE expression instead of dynamic SQL in SQL Server</title>
<link>https://www.sqlservercentral.com/articles/using-the-case-expression-instead-of-dynamic-sql-in-sql-server</link>
<dc:creator><![CDATA[Additional Articles]]></dc:creator>
<pubDate>Wed, 23 Apr 2025 00:00:31 +0000</pubDate>
<category><![CDATA[T-SQL]]></category>
<guid isPermaLink="false">https://www.sqlservercentral.com/?post_type=ssc_article&p=4568817</guid>
<description><![CDATA[<p>I have a lot of SQL update queries where I need to make IF/ELSE types of decisions. In some cases, I am using a cursor but looping through thousands of rows for update takes a long time. I also use some dynamic SQL to handle some query parameter decision making. Is there a better alternative?</p>
<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/using-the-case-expression-instead-of-dynamic-sql-in-sql-server">Using the CASE expression instead of dynamic SQL in SQL Server</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></description>
<content:encoded><![CDATA[<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/using-the-case-expression-instead-of-dynamic-sql-in-sql-server">Using the CASE expression instead of dynamic SQL in SQL Server</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></content:encoded>
</item>
<item>
<title>Understanding CROSS APPLY and OUTER APPLY in SQL Server</title>
<link>https://www.sqlservercentral.com/articles/understanding-cross-apply-and-outer-apply-in-sql-server</link>
<dc:creator><![CDATA[Noman072]]></dc:creator>
<pubDate>Mon, 21 Apr 2025 00:00:41 +0000</pubDate>
<category><![CDATA[cross apply]]></category>
<category><![CDATA[T-SQL]]></category>
<category><![CDATA[CROSS APPLY]]></category>
<category><![CDATA[INNER JOIN]]></category>
<category><![CDATA[left join]]></category>
<category><![CDATA[OUTER APPLY]]></category>
<category><![CDATA[SQL Basics]]></category>
<category><![CDATA[SQL Function]]></category>
<category><![CDATA[SQL Join]]></category>
<category><![CDATA[SQL optimization]]></category>
<category><![CDATA[SQL performance]]></category>
<category><![CDATA[SQL programming]]></category>
<category><![CDATA[SQL Queries]]></category>
<category><![CDATA[SQL Query Examples]]></category>
<category><![CDATA[SQL Server]]></category>
<category><![CDATA[SQL Subquery]]></category>
<category><![CDATA[SQL tutorial]]></category>
<category><![CDATA[Table-Valued Functions]]></category>
<category><![CDATA[TVF]]></category>
<guid isPermaLink="false">https://www.sqlservercentral.com/?post_type=ssc_article&p=4544634</guid>
<description><![CDATA[<p>Learn the differences between CROSS APPLY and OUTER APPLY in SQL.</p>
<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/understanding-cross-apply-and-outer-apply-in-sql-server">Understanding CROSS APPLY and OUTER APPLY in SQL Server</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></description>
<content:encoded><![CDATA[<h2 data-start="609" data-end="630"><strong data-start="614" data-end="630">Introduction</strong></h2>
<p>When working with table-valued functions (TVFs) or subqueries, the CROSS APPLY and OUTER APPLY operators provide flexible ways to enhance SQL queries. While these operators might seem complex at first, understanding how they function can significantly improve both query performance and readability.</p>
<p>In this article, we will break down how each operator works with practical examples and clearly explain their behavior when using TVFs, a common scenario. We will also address common points of confusion to help you gain a solid understanding of these operators.</p>
<h2 data-start="1207" data-end="1255"><strong data-start="1212" data-end="1255">What are Table-Valued Functions (TVFs)?</strong></h2>
<p>A table-valued function (TVF) is a special type of SQL function that returns a table as its result. TVFs are used to encapsulate complex logic and make queries more modular. You can use a TVF like a regular table in a query, which makes it a powerful tool when combined with CROSS APPLY or OUTER APPLY.</p>
<p>Let’s clarify how the APPLY operators interact with TVFs:</p>
<ul>
<li>CROSS APPLY: Joins each row from the left table with the result set from the TVF. It will only return rows where there is a match between the left table and the right-side expression (the result of the TVF).</li>
<li>OUTER APPLY: Similar to CROSS APPLY, but ensures that all rows from the left table are returned, even if there is no matching row in the right-side expression (the TVF).</li>
</ul>
<p data-start="2028" data-end="2081"><strong>Step 1: Create Sample Tables and Insert Data</strong></p>
<p>Before diving into examples, we need to set up a database with some sample data. Let’s create two tables: Departments and Employees.</p>
<pre class="prettyprint lang-mssql">-- Create the Departments table
DROP TABLE IF EXISTS #Departments;
CREATE TABLE #Departments (DepartmentID INT, Name NVARCHAR(50));
INSERT INTO #Departments (DepartmentID, Name)
VALUES
(1, 'Engineering'),
(2, 'Sales'),
(3, 'HR'),
(4, 'Marketing'); -- Marketing department without employees
-- Create the Employees table
DROP TABLE IF EXISTS #Employees;
CREATE TABLE #Employees (EmployeeID INT, FirstName NVARCHAR(50), LastName NVARCHAR(50), DepartmentID INT, YearlySalary INT);
INSERT INTO #Employees (EmployeeID, FirstName, LastName, DepartmentID, YearlySalary)
VALUES
(1, 'John', 'Doe', 1, 80000),
(2, 'Jane', 'Smith', 1, 90000),
(3, 'Paul', 'Johnson', 2, 75000),
(4, 'Emma', 'Wilson', 3, 70000);
</pre>
<p>Explanation: This step sets up two tables:</p>
<p>Departments: Holds department data.</p>
<p>Employees: Holds employee data, including the department they belong to and their salary.</p>
<p data-start="3125" data-end="3180"><strong>Step 2: Create the Table-Valued Function (TVF)</strong></p>
<p>Next, we will create a TVF that returns the top 2 employees by salary for any given department.</p>
<pre class="prettyprint lang-mssql">-- Create or alter the function with the permanent Employees table
CREATE OR ALTER FUNCTION dbo.fn_GetTopEmployeeSalary (@DeptID INT)
RETURNS TABLE
AS
RETURN
(SELECT TOP 2
CONCAT(FirstName, ' ', LastName) AS EmployeeName,
YearlySalary
FROM dbo.Employees
WHERE DepartmentID = @DeptID
ORDER BY YearlySalary DESC);
GO
</pre>
<p>Explanation:</p>
<ul>
<li>The fn_GetTopEmployeeSalary TVF returns the top two highest-paid employees for a given department.</li>
<li>It accepts a DepartmentID as an input parameter to filter employees based on the department.</li>
<li>The employees are ordered by salary in descending order.</li>
<li>The function returns a table with the employee's full name (concatenation of their first and last names) and their salary.</li>
<li>Since SQL Server functions cannot access temporary tables, this function uses a permanent table (dbo.Employees), ensuring it can be accessed across sessions.</li>
</ul>
<p><strong>Step 3: Using CROSS APPLY with a TVF</strong></p>
<p>Now, let’s use the CROSS APPLY operator with our table-valued function (TVF). This query will return the top 2 highest-paid employees for each department.</p>
<pre class="prettyprint lang-mssql">-- Using CROSS APPLY to get top 2 highest paid employees for each department
SELECT D.Name AS DepartmentName,
E.EmployeeName,
E.YearlySalary
FROM #Departments D
CROSS APPLY dbo.fn_GetTopEmployeeSalary(D.DepartmentID) E;
</pre>
<p>Explanation: Here’s what happens:</p>
<ul>
<li>CROSS APPLY works like an INNER JOIN. For each row in the Departments table (D), it applies the TVF dbo.fn_GetTopEmployeeSalary(D.DepartmentID) for that department.</li>
<li>The query will return only those departments that have matching employees.</li>
</ul>
<p class="" data-start="4337" data-end="4374">Expected Result:</p>
<p id="XQWjvPe"><a href="https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef764230899.png"><img loading="lazy" width="593" height="574" class="alignnone size-full wp-image-4573015 " src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef764230899.png" data-lazy-load alt="" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef764230899.png 593w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef764230899-300x290.png 300w" sizes="(max-width: 593px) 100vw, 593px" /></a></p>
<p>Key Point: CROSS APPLY ensures that only departments with employees are included. If a department has no employees (e.g., Marketing), it won’t show up in the result.</p>
<p><strong>Step 4: Using OUTER APPLY with a TVF</strong></p>
<p>Let’s now use OUTER APPLY instead of CROSS APPLY. This operator behaves like a LEFT JOIN, ensuring that all departments are included, even those without employees.</p>
<pre class="prettyprint lang-mssql">-- Using OUTER APPLY to get all departments, including those without employees
SELECT D.Name AS DepartmentName,
E.EmployeeName,
E.YearlySalary
FROM #Departments D
OUTER APPLY dbo.fn_GetTopEmployeeSalary(D.DepartmentID) E;
</pre>
<p>Explanation:</p>
<ul>
<li>OUTER APPLY returns all rows from the left table (Departments), even if there’s no matching data in the right table (the result of the TVF).</li>
<li>If a department has no employees, NULL values will be returned for EmployeeName and YearlySalary.</li>
</ul>
<p class="" data-start="5571" data-end="5588">Expected Result:</p>
<p id="kRUkoDf"><a href="https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef76727ed95.png"><img loading="lazy" width="621" height="574" class="alignnone size-full wp-image-4573016 " src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef76727ed95.png" data-lazy-load alt="" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef76727ed95.png 621w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef76727ed95-300x277.png 300w" sizes="(max-width: 621px) 100vw, 621px" /></a></p>
<p>Key Point: OUTER APPLY ensures that all departments are returned, even those without employees (like the Marketing department).</p>
<p data-start="6318" data-end="6375"><strong>Step 5: Inserting a Department with No Employees</strong></p>
<p>Let’s insert a new department, Finance, which has no employees, and observe how both CROSS APPLY and OUTER APPLY behave.</p>
<pre class="prettyprint lang-mssql">-- Insert an empty department (no employees)
INSERT INTO #Departments (DepartmentID, Name)
VALUES (5, 'Finance');
</pre>
<p>Let’s rerun both the CROSS APPLY and OUTER APPLY queries.</p>
<p><strong>Using CROSS APPLY with the New Data:</strong></p>
<pre class="prettyprint lang-mssql">-- Using CROSS APPLY to get top 2 highest paid employees for each department
SELECT D.Name AS DepartmentName,
E.EmployeeName,
E.YearlySalary
FROM #Departments D
CROSS APPLY dbo.fn_GetTopEmployeeSalary(D.DepartmentID) E;
</pre>
<p>Explanation: The Finance department doesn’t appear because it has no employees, and CROSS APPLY works like an INNER JOIN.</p>
<p>Expected Result:</p>
<p><a href="https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef7694a1377.png"><img loading="lazy" width="630" height="575" class="alignnone size-full wp-image-4573017 " src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef7694a1377.png" data-lazy-load alt="" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef7694a1377.png 630w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef7694a1377-300x274.png 300w" sizes="(max-width: 630px) 100vw, 630px" /></a></p>
<p>Using OUTER APPLY with the New Data:</p>
<pre class="prettyprint lang-mssql">-- Using OUTER APPLY to get all departments, including those without employees
SELECT D.Name AS DepartmentName,
E.EmployeeName,
E.YearlySalary
FROM #Departments D
OUTER APPLY dbo.fn_GetTopEmployeeSalary(D.DepartmentID) E;
</pre>
<p>Explanation: The Finance department now appears in the results with NULL values for the employee fields, as OUTER APPLY ensures all departments are included, regardless of employee availability.</p>
<p>Expected Result:</p>
<p id="FoKiFbw"><a href="https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef76ac1fb20.png"><img loading="lazy" width="640" height="574" class="alignnone size-full wp-image-4573018 " src="data:image/gif;base64,R0lGODlhAQABAPAAAPLy8v///yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" data-src="https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef76ac1fb20.png" data-lazy-load alt="" data-srcset="https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef76ac1fb20.png 640w, https://www.sqlservercentral.com/wp-content/uploads/2025/04/img_67ef76ac1fb20-300x269.png 300w" sizes="(max-width: 640px) 100vw, 640px" /></a></p>
<h2 data-start="8912" data-end="8930"><strong>Key Points</strong></h2>
<ol>
<li>CROSS APPLY returns matching rows only (like an INNER JOIN).</li>
<li>OUTER APPLY returns all rows from the left table, even if no matches exist in the right-side table (like a LEFT JOIN).</li>
<li>TVFs are often used with these operators to provide dynamic results based on a function’s return value.</li>
</ol>
<h2 data-start="8934" data-end="8998"><code data-start="8934" data-end="8947"></code><strong data-start="8301" data-end="8315">Conclusion</strong></h2>
<p>The CROSS APPLY and OUTER APPLY operators are incredibly useful for working with subqueries and table-valued functions (TVFs) in SQL. Here's a quick recap:</p>
<ul>
<li>Use CROSS APPLY when you need to match rows from both the left table and the right table expression (similar to an INNER JOIN).</li>
<li>Use OUTER APPLY when you need to include all rows from the left table, even if there’s no matching row in the right-side expression (similar to a LEFT JOIN).</li>
</ul>
<p>These operators are particularly useful in complex queries and enhance the performance and readability of your SQL code.</p>
<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/understanding-cross-apply-and-outer-apply-in-sql-server">Understanding CROSS APPLY and OUTER APPLY in SQL Server</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></content:encoded>
</item>
<item>
<title>Load Data into Snowflake Using Python with Pandas</title>
<link>https://www.sqlservercentral.com/articles/load-data-into-snowflake-using-python-with-pandas</link>
<dc:creator><![CDATA[Additional Articles]]></dc:creator>
<pubDate>Mon, 21 Apr 2025 00:00:37 +0000</pubDate>
<category><![CDATA[Python]]></category>
<category><![CDATA[Snowflake]]></category>
<guid isPermaLink="false">https://www.sqlservercentral.com/?post_type=ssc_article&p=4575512</guid>
<description><![CDATA[<p>Loading data into Snowflake is a common need. Using Python and pandas is a common go-to solution for data professionals</p>
<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/load-data-into-snowflake-using-python-with-pandas">Load Data into Snowflake Using Python with Pandas</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></description>
<content:encoded><![CDATA[<p>The post <a rel="nofollow" href="https://www.sqlservercentral.com/articles/load-data-into-snowflake-using-python-with-pandas">Load Data into Snowflake Using Python with Pandas</a> appeared first on <a rel="nofollow" href="https://www.sqlservercentral.com">SQLServerCentral</a>.</p>
]]></content:encoded>
</item>
</channel>
</rss>
<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/
Page Caching using Redis (Page is feed)
Served from: sqlservercentral.com @ 2025-04-30 19:09:37 by W3 Total Cache
-->
If you would like to create a banner that links to this page (i.e. this validation result), do the following:
Download the "valid RSS" banner.
Upload the image to your own server. (This step is important. Please do not link directly to the image on this server.)
Add this HTML to your page (change the image src
attribute if necessary):
If you would like to create a text link instead, here is the URL you can use:
http://www.feedvalidator.org/check.cgi?url=https%3A//www.sqlservercentral.com/feed