{"id":6657,"date":"2022-03-07T06:30:00","date_gmt":"2022-03-07T05:30:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=6657"},"modified":"2023-03-23T07:39:30","modified_gmt":"2023-03-23T06:39:30","slug":"how-to-create-a-sql-server-function","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/","title":{"rendered":"How to create a SQL Server function with a script ?"},"content":{"rendered":"\n<h4 class=\"has-text-align-center wp-block-heading\" id=\"h-example-of-t-sql-code-to-create-a-simple-sql-server-user-defined-function\"><strong><em>Example of T-SQL code to create a simple SQL Server user defined function.<\/em><\/strong><\/h4>\n\n\n\n<p>Tutorial to create a simple SQL Server function with a T-SQL script. You can use the code provided as a syntax checklist or an example to copy and paste. In fact, the script creates a SQL function with a customer number as a parameter and the customer&#8217;s name as the result.<\/p>\n\n\n\n<p>T-SQL functions, like stored procedures, are at the heart of Microsoft database programming. They allow to manage the intelligence of the databases and to reuse the code with a single keyword. The basic principle is to reuse code instead of programming the same thing over and over again.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Add a source table to use in the function<\/h2>\n\n\n\n<p>To start, create the customers table with the code available on this page with the code for creating the Customers example table. The code allows you to have the source table used by the view. The source table in your case will be adapted with your own objects. This type of function is a <a href=\"https:\/\/cloud.google.com\/bigquery\/docs\/reference\/standard-sql\/user-defined-functions?hl=en\" target=\"_blank\" rel=\"noreferrer noopener\">user defined<\/a> function. The name is stored in the return variable @CustomerName. Use the sample table creation code available here : <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- If the Customers table already exists, then we drop it\nIF exists(   \n     SELECT  1 FROM sys.objects\n     WHERE   object_id = object_id(N'[dbo].[CUSTOMERS]') AND type in (N'U')\n)\nBEGIN\n     DROP TABLE [dbo].[CUSTOMERS]\nEND\nGO\n\n-- We Create the CUSTOMERS table with the Column [Name] declared as Unique\n-- The UNIQUE keyword don't allow to have two different customers with the same name\nCREATE TABLE [dbo].[CUSTOMERS] (\n     [CustomerNumber]       INTEGER IDENTITY(1,1),\n     [Name]      NVARCHAR(20) UNIQUE,\n     [City]      NVARCHAR(20)\n)\nGO\n\n-- Data insertion for the function example\nINSERT INTO dbo.CUSTOMERS ( [Name], [City] ) VALUES ( N'John', 'New York');\nINSERT INTO dbo.CUSTOMERS ( [Name], [City] ) VALUES ( N'Ahmed', 'Los Angeles');\nINSERT INTO dbo.CUSTOMERS ( [Name], [City] ) VALUES ( N'Jane', 'Miami');\nINSERT INTO dbo.CUSTOMERS ( [Name], [City] ) VALUES ( N'Lee', 'Chicago');\nINSERT INTO dbo.CUSTOMERS ( [Name], [City] ) VALUES ( N'Diana', 'San Francisco');\n\n-- Let's verify the inserted lines for our 5 customers\nSELECT * \nFROM dbo.CUSTOMERS;\n<\/pre>\n\n\n\n<p>This sample function in the next section accepts as input the customer number and returns the customer name.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. Create the function using a T-SQL script<\/h2>\n\n\n\n<p>The 6 important steps in the SQL Server function declaration below are the following.\u00a0<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>We define the entry parameter as an Integer, i.e. <em>@CustomerNumber<\/em>.<\/li>\n\n\n\n<li>We declare the return type, here it is the NVARCHAR(20) data type.<\/li>\n\n\n\n<li>Then we declare the variable <em>@CustomerName<\/em>, also with the NVARCHAR(20) data type.<\/li>\n\n\n\n<li>Select the Customer name from the CUSTOMERS table using the <em>@CustomerNumber<\/em> variable. Indeed, a customer as a unique customer number so we use it as the key for the selection.<\/li>\n\n\n\n<li>In the SELECT query, the customer name is stored into the <em>@CustomerName<\/em> variable.<\/li>\n\n\n\n<li>Then we return customer name using the variable.<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CREATE FUNCTION dbo.ufnDisplayCustomers(@CustomerNumber INTEGER)\nRETURNS NVARCHAR(20)\nAS \nBEGIN \n  DECLARE @CustomerName  AS NVARCHAR(20);\n  SELECT  @CustomerName = [Name]\n  FROM    [dbo].[CUSTOMERS]\n  WHERE   [CustomerNumber] = @CustomerNumber;\n  RETURN  @CustomerName;\nEND\nGO\n<\/pre>\n\n\n\n<p>Once created, you can easily <a href=\"https:\/\/expert-only.com\/en\/t-sql\/call-sql-server-function\/\">call and test the SQL Server function<\/a> using this script.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT dbo.ufnDisplayCustomers(1);\n<\/pre>\n\n\n\n<p>Note that the syntax for calling a function is the same as for a table. The difference is the passing of the parameter. For a function with no parameter then the parentheses remain empty. To go further, there are different types of SQL functions to study. This article shows how to create a SQL Server function, check here this article on <a href=\"https:\/\/expert-only.com\/en\/ms-dos\/create-text-list-of-files-with-cmd\/\">how to create a text list of files available in one folder in cmd<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion on creating a function with T-SQL<\/h2>\n\n\n\n<p>In conclusion, learning how to create a simple SQL Server function with a T-SQL script is a fundamental skill for database developers and administrators. This tutorial demonstrated the process of creating a user-defined function that takes a customer number as a parameter and returns the corresponding customer&#8217;s name. By leveraging T-SQL functions, you can encapsulate complex logic and promote code reusability across all your database applications. Which one of the most important good practice in progamming.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"Me3KgpwDPb\"><a href=\"https:\/\/expert-only.com\/en\/t-sql\/modify-sql-server-function\/\">Modify a SQL Server function with alter function<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Modify a SQL Server function with alter function&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/t-sql\/modify-sql-server-function\/embed\/#?secret=b24nqSo1eP#?secret=Me3KgpwDPb\" data-secret=\"Me3KgpwDPb\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1649609531868\"><strong class=\"schema-faq-question\">What is the difference between a function and a SQL Server stored procedure?<\/strong> <p class=\"schema-faq-answer\">The main difference between a function and a SQL Server stored procedure is that a function takes an input parameter and returns a result. Whereas a stored procedure does not necessarily return a result or even take an input parameter. A stored procedure is a set of one or multiple T-SQL statements executed as one batch.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Example of T-SQL code to create a simple SQL Server user defined function. Tutorial to create a simple SQL Server function with a T-SQL script. You can use the code provided as a syntax checklist or an example to <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/\" title=\"How to create a SQL Server function with a script ?\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":5602,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[454],"tags":[],"class_list":{"0":"post-6657","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>How to create a SQL Server function with a script ? T-SQL<\/title>\n<meta name=\"description\" content=\"How to create a SQL Server function with a script ?\u00a0Code that takes as an input parameter the customer number and returns the customer name.\" \/>\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\/how-to-create-a-sql-server-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to create a SQL Server function with a script ?\" \/>\n<meta property=\"og:description\" content=\"How to create a SQL Server function with a script ?\u00a0Code that takes as an input parameter the customer number and returns the customer name.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/\" \/>\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=\"2022-03-07T05:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-23T06:39:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/metal-white-coffee-cup-25CB1BEFD9A_1920x1080.jpeg\" \/>\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=\"4 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\/how-to-create-a-sql-server-function\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\"},\"headline\":\"How to create a SQL Server function with a script ?\",\"datePublished\":\"2022-03-07T05:30:00+00:00\",\"dateModified\":\"2023-03-23T06:39:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/\"},\"wordCount\":579,\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/metal-white-coffee-cup-25CB1BEFD9A_1920x1080.jpeg\",\"articleSection\":[\"T-SQL\"],\"inLanguage\":\"en-US\"},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/\",\"url\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/\",\"name\":\"How to create a SQL Server function with a script ? T-SQL\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/metal-white-coffee-cup-25CB1BEFD9A_1920x1080.jpeg\",\"datePublished\":\"2022-03-07T05:30:00+00:00\",\"dateModified\":\"2023-03-23T06:39:30+00:00\",\"description\":\"How to create a SQL Server function with a script ?\u00a0Code that takes as an input parameter the customer number and returns the customer name.\",\"breadcrumb\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#faq-question-1649609531868\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#primaryimage\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/metal-white-coffee-cup-25CB1BEFD9A_1920x1080.jpeg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/metal-white-coffee-cup-25CB1BEFD9A_1920x1080.jpeg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\/\/expert-only.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to create a SQL Server function with a script ?\"}]},{\"@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\"}},{\"@type\":\"Question\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#faq-question-1649609531868\",\"position\":1,\"url\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#faq-question-1649609531868\",\"name\":\"What is the difference between a function and a SQL Server stored procedure?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The main difference between a function and a SQL Server stored procedure is that a function takes an input parameter and returns a result. Whereas a stored procedure does not necessarily return a result or even take an input parameter. A stored procedure is a set of one or multiple T-SQL statements executed as one batch.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to create a SQL Server function with a script ? T-SQL","description":"How to create a SQL Server function with a script ?\u00a0Code that takes as an input parameter the customer number and returns the customer name.","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\/how-to-create-a-sql-server-function\/","og_locale":"en_US","og_type":"article","og_title":"How to create a SQL Server function with a script ?","og_description":"How to create a SQL Server function with a script ?\u00a0Code that takes as an input parameter the customer number and returns the customer name.","og_url":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2022-03-07T05:30:00+00:00","article_modified_time":"2023-03-23T06:39:30+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/metal-white-coffee-cup-25CB1BEFD9A_1920x1080.jpeg","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":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"How to create a SQL Server function with a script ?","datePublished":"2022-03-07T05:30:00+00:00","dateModified":"2023-03-23T06:39:30+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/"},"wordCount":579,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/metal-white-coffee-cup-25CB1BEFD9A_1920x1080.jpeg","articleSection":["T-SQL"],"inLanguage":"en-US"},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/","url":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/","name":"How to create a SQL Server function with a script ? T-SQL","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/metal-white-coffee-cup-25CB1BEFD9A_1920x1080.jpeg","datePublished":"2022-03-07T05:30:00+00:00","dateModified":"2023-03-23T06:39:30+00:00","description":"How to create a SQL Server function with a script ?\u00a0Code that takes as an input parameter the customer number and returns the customer name.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#faq-question-1649609531868"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/metal-white-coffee-cup-25CB1BEFD9A_1920x1080.jpeg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/08\/metal-white-coffee-cup-25CB1BEFD9A_1920x1080.jpeg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"How to create a SQL Server function with a script ?"}]},{"@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"}},{"@type":"Question","@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#faq-question-1649609531868","position":1,"url":"https:\/\/expert-only.com\/en\/t-sql\/how-to-create-a-sql-server-function\/#faq-question-1649609531868","name":"What is the difference between a function and a SQL Server stored procedure?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The main difference between a function and a SQL Server stored procedure is that a function takes an input parameter and returns a result. Whereas a stored procedure does not necessarily return a result or even take an input parameter. A stored procedure is a set of one or multiple T-SQL statements executed as one batch.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/6657","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=6657"}],"version-history":[{"count":0,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/6657\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/5602"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=6657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=6657"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=6657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}