{"id":27829,"date":"2023-08-21T06:50:00","date_gmt":"2023-08-21T04:50:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=27829"},"modified":"2023-10-31T12:38:15","modified_gmt":"2023-10-31T11:38:15","slug":"sql-server-stored-procedures-examples","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/","title":{"rendered":"SQL Server Stored Procedure Examples"},"content":{"rendered":"\n<p>These simple SQL Server Stored procedure examples are powerful tools that can simplify your database development work. For example when dealing with complex business logic embedded into the SQL code. A stored procedure is a group of Transact-SQL statements compiled into a single execution plan. <\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#1-structure-of-a-basic-sql-server-stored-procedure\" >1. Structure of a Basic SQL Server Stored Procedure<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#2-working-with-parameters-in-stored-procedures\" >2. Working with Parameters in Stored Procedures<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#3-handling-errors-in-sql-stored-procedures\" >3. Handling Errors in SQL Stored Procedures<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#4-use-conditional-logic-in-a-sql-procedure\" >4. Use Conditional Logic in a SQL Procedure<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#5-t-sql-procedure-with-a-loop\" >5. T-SQL Procedure with a Loop<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#conclusion-on-using-sql-server-stored-procedures\" >Conclusion on using SQL Server Stored Procedures<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-1-structure-of-a-basic-sql-server-stored-procedure\"><span class=\"ez-toc-section\" id=\"1-structure-of-a-basic-sql-server-stored-procedure\"><\/span>1. Structure of a Basic SQL Server Stored Procedure<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let&#8217;s start with the basic structure of an MS SQL stored procedure. The CREATE PROCEDURE statement is used to create a stored procedure. It&#8217;s followed by the procedure name and, optionally, parameters that you want to pass to the procedure. Below is a simple example to create a generic procedure called <em>MyProcedure<\/em>.<\/p>\n\n\n\n<p>In the example, the stored procedure named <em>MyProcedure<\/em> simply selects all records from the SQL table <em>MyTable<\/em>. The BEGIN and END keywords enclose the SQL statements.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE PROCEDURE MyProcedure\nAS\n\nBEGIN\n  SELECT * FROM MyTable\nEND\n\nGO<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-2-working-with-parameters-in-stored-procedures\"><span class=\"ez-toc-section\" id=\"2-working-with-parameters-in-stored-procedures\"><\/span>2. Working with Parameters in Stored Procedures<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedure-parameters\/\"><strong>Parameters can be used to pass values to the stored procedure<\/strong><\/a>. Now let&#8217;s modify <em>MyProcedure<\/em> to accept a unique parameter. As you can see, the @MyParam parameter is of type INT. It is used in the WHERE clause to filter records from <em>MyTable<\/em>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE PROCEDURE MyProcedure\n   @MyParam INT\nAS\nBEGIN\n   SELECT *\n   FROM   MyTable\n   WHERE  MyColumn = @MyParam\nEND\nGO<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-3-handling-errors-in-sql-stored-procedures\"><span class=\"ez-toc-section\" id=\"3-handling-errors-in-sql-stored-procedures\"><\/span>3. Handling Errors in SQL Stored Procedures <span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Error handling is a vital aspect of writing robust T-SQL code. Fortunately, <strong>SQL Server provides TRY CATCH<\/strong> constructs for this purpose. Here, the TRY block contains the SQL code that might cause an exception.<\/p>\n\n\n\n<p>Technically, it means that if an error occurs, the control is passed to the CATCH block where the error can be handled.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE PROCEDURE MyProcedure\n   @MyParam INT\nAS\n\nBEGIN TRY\n  SELECT *\n  FROM   MyTable\n  WHERE  MyColumn = @MyParam\nEND TRY\n\nBEGIN CATCH\n  SELECT ERROR_MESSAGE() AS ErrorMessage;\nEND CATCH\n\nGO<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-4-use-conditional-logic-in-a-sql-procedure\"><span class=\"ez-toc-section\" id=\"4-use-conditional-logic-in-a-sql-procedure\"><\/span>4. Use Conditional Logic in a SQL Procedure<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>SQL server stored procedure examples often use IF ELSE statements for conditional logic.<\/strong> This can greatly increase efficiency and maintainability.<\/p>\n\n\n\n<p>Indeed, the IF-ELSE statement checks whether @MyParam is NULL. If it is not, a filtered select statement is executed. If it is NULL, all records are returned. Otherwise, the results would not return anything, another option is to set a default value for the parameter. <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE PROCEDURE MyProcedure @MyParam INT\nAS\nBEGIN\n   IF @MyParam IS NOT NULL\n      BEGIN\n        SELECT *\n\t   FROM   MyTable \n\t   WHERE  MyColumn = @MyParam\n      END\n   ELSE\n      BEGIN\n        SELECT *\n\t   FROM   MyTable\n      END\nEND\nGO<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-5-t-sql-procedure-with-a-loop\"><span class=\"ez-toc-section\" id=\"5-t-sql-procedure-with-a-loop\"><\/span>5. T-SQL Procedure with a Loop<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Looping constructs, like WHILE loops, can be used in SQL stored procedures to iterate over a set of records. This <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/t-sql\/statements\/while-transact-sql?view=sql-server-ver15\" target=\"_blank\" rel=\"noreferrer noopener\">Microsoft documentation<\/a> provides more insight on this.<\/p>\n\n\n\n<p>So in this last example, a stored procedure named <em>PrintIterations<\/em> is created. When this procedure is executed, it will print a message for each iteration, 10 times in total.<\/p>\n\n\n\n<p>The GO statement is a batch separator which signifies the end of the stored procedure creation and the beginning of any subsequent SQL commands. The command EXEC PrintIterations is a simple call to the stored procedure to execute its logic.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE PROCEDURE PrintIterations\nAS\nBEGIN\n    DECLARE @Counter INT = 1\n\n    WHILE @Counter &lt;= 10\n    BEGIN\n        PRINT 'This is loop iteration ' + CAST(@Counter AS NVARCHAR(2))\n        SET @Counter = @Counter + 1\n    END\nEND\nGO\n\n-- To execute the stored procedure\nEXEC PrintIterations\n<\/pre>\n\n\n\n<p><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"820\" height=\"660\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/10\/sql-server_stored-procedure-loop-while.jpg\" alt=\"SQL Server stored procedures examples using a WHILE loop\" class=\"wp-image-27834\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/10\/sql-server_stored-procedure-loop-while.jpg 820w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/10\/sql-server_stored-procedure-loop-while-300x241.jpg 300w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/10\/sql-server_stored-procedure-loop-while-768x618.jpg 768w\" sizes=\"auto, (max-width: 820px) 100vw, 820px\" \/><figcaption class=\"wp-element-caption\"><em>SQL Server stored procedures examples using a WHILE loop<\/em><\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion-on-using-sql-server-stored-procedures\"><span class=\"ez-toc-section\" id=\"conclusion-on-using-sql-server-stored-procedures\"><\/span>Conclusion on using SQL Server Stored Procedures<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><b>Useful SQL stored procedures<\/b> can greatly enhance the efficiency, readability and maintenance of your SQL server code. They allow encapsulation of complex business logic into reusable and modular programs. From handling errors, using conditional logic, to looping constructs, basic stored procedures in SQL server offer a range of possibilities. Consider using them in your next SQL server project for cleaner and more efficient code.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>These simple SQL Server Stored procedure examples are powerful tools that can simplify your database development work. For example when dealing with complex business logic embedded into the SQL code. A stored procedure is a group of Transact-SQL statements <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/\" title=\"SQL Server Stored Procedure Examples\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":10924,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[454],"tags":[],"class_list":{"0":"post-27829","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-t-sql"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.7 (Yoast SEO v26.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL Server Stored Procedure Examples - T-SQL<\/title>\n<meta name=\"description\" content=\"Database tutorial with simple SQL Server stored procedures, with script examples to create them in T-SQL using SSMS.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server Stored Procedure Examples\" \/>\n<meta property=\"og:description\" content=\"Database tutorial with simple SQL Server stored procedures, with script examples to create them in T-SQL using SSMS.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL and IT Tutorials\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-21T04:50:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-10-31T11:38:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/watch-C16A734EA20_1920x1080.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Expert-Only\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@expert_only\" \/>\n<meta name=\"twitter:site\" content=\"@expert_only\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Expert-Only\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\"},\"headline\":\"SQL Server Stored Procedure Examples\",\"datePublished\":\"2023-08-21T04:50:00+00:00\",\"dateModified\":\"2023-10-31T11:38:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/\"},\"wordCount\":502,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/watch-C16A734EA20_1920x1080.jpg\",\"articleSection\":[\"T-SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/\",\"url\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/\",\"name\":\"SQL Server Stored Procedure Examples - T-SQL\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/watch-C16A734EA20_1920x1080.jpg\",\"datePublished\":\"2023-08-21T04:50:00+00:00\",\"dateModified\":\"2023-10-31T11:38:15+00:00\",\"description\":\"Database tutorial with simple SQL Server stored procedures, with script examples to create them in T-SQL using SSMS.\",\"breadcrumb\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#primaryimage\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/watch-C16A734EA20_1920x1080.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/watch-C16A734EA20_1920x1080.jpg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\/\/expert-only.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server Stored Procedure Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/expert-only.com\/en\/#website\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"name\":\"SQL and IT Tutorials\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/expert-only.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/expert-only.com\/en\/#organization\",\"name\":\"Expert-Only\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"width\":381,\"height\":174,\"caption\":\"Expert-Only\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\",\"https:\/\/x.com\/expert_only\",\"https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\",\"name\":\"Expert-Only\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"caption\":\"Expert-Only\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL Server Stored Procedure Examples - T-SQL","description":"Database tutorial with simple SQL Server stored procedures, with script examples to create them in T-SQL using SSMS.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server Stored Procedure Examples","og_description":"Database tutorial with simple SQL Server stored procedures, with script examples to create them in T-SQL using SSMS.","og_url":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2023-08-21T04:50:00+00:00","article_modified_time":"2023-10-31T11:38:15+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/watch-C16A734EA20_1920x1080.jpg","type":"image\/jpeg"}],"author":"Expert-Only","twitter_card":"summary_large_image","twitter_creator":"@expert_only","twitter_site":"@expert_only","twitter_misc":{"Written by":"Expert-Only","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"SQL Server Stored Procedure Examples","datePublished":"2023-08-21T04:50:00+00:00","dateModified":"2023-10-31T11:38:15+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/"},"wordCount":502,"commentCount":0,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/watch-C16A734EA20_1920x1080.jpg","articleSection":["T-SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/","url":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/","name":"SQL Server Stored Procedure Examples - T-SQL","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/watch-C16A734EA20_1920x1080.jpg","datePublished":"2023-08-21T04:50:00+00:00","dateModified":"2023-10-31T11:38:15+00:00","description":"Database tutorial with simple SQL Server stored procedures, with script examples to create them in T-SQL using SSMS.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/watch-C16A734EA20_1920x1080.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/watch-C16A734EA20_1920x1080.jpg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-stored-procedures-examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"SQL Server Stored Procedure Examples"}]},{"@type":"WebSite","@id":"https:\/\/expert-only.com\/en\/#website","url":"https:\/\/expert-only.com\/en\/","name":"SQL and IT Tutorials","description":"","publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/expert-only.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/expert-only.com\/en\/#organization","name":"Expert-Only","url":"https:\/\/expert-only.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","width":381,"height":174,"caption":"Expert-Only"},"image":{"@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ExpertOnlyCom\/","https:\/\/x.com\/expert_only","https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA"]},{"@type":"Person","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef","name":"Expert-Only","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","caption":"Expert-Only"}}]}},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/27829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/comments?post=27829"}],"version-history":[{"count":7,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/27829\/revisions"}],"predecessor-version":[{"id":27858,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/27829\/revisions\/27858"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/10924"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=27829"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=27829"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=27829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}