---
title: "what is scalar function in sql"  
description: "Here we are going to explain what is scalar function in sql or how to create scalar function in sql or how to use scalar function in sql server with e"  
author: "Anonymous User"  
published: 2018-07-09  
updated: 2019-07-04  
canonical: https://www.mindstick.com/articles/12998/what-is-scalar-function-in-sql  
category: "mssql server"  
tags: ["sql server", "sql"]  
reading_time: 1 minute  

---

# what is scalar function in sql

## Introduction:

Here we are going to explain what is[scalar](https://www.mindstick.com/forum/34598/how-to-create-scalar-function-in-sql) [function](https://www.mindstick.com/forum/34598/how-to-create-scalar-function-in-sql) in sql or how to create scalar function in sql or how to use [scalar](https://www.mindstick.com/forum/34598/how-to-create-scalar-function-in-sql) [function in](https://www.mindstick.com/forum/34598/how-to-create-scalar-function-in-sql) [sql](https://www.mindstick.com/forum/34598/how-to-create-scalar-function-in-sql) [server](https://www.mindstick.com/forum/34598/how-to-create-scalar-function-in-sql) with example.

## Description:

[SQL Server scalar function](https://www.mindstick.com/forum/34598/how-to-create-scalar-function-in-sql) is a function that operates on scalar values -- that is, it takes one (or more) input values as parameters directly and returns a value.

**Example of [scalar](https://www.mindstick.com/forum/34598/how-to-create-scalar-function-in-sql) [function](https://www.mindstick.com/forum/34598/how-to-create-scalar-function-in-sql):**

```
CREATE FUNCTION [dbo].[RemoveHtmlFronString] (@HTMLText VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN
DECLARE @Start INT
DECLARE @End INT
DECLARE @Length INT
SET @Start = CHARINDEX('<',@HTMLText) SET @End =
CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText))
SET @Length = (@End - @Start) + 1 WHILE @Start > 0
AND @End > 0
AND @Length > 0
BEGIN
SET @HTMLText = STUFF(@HTMLText,@Start,@Length,'')
SET @Start = CHARINDEX('<',@HTMLText) SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText))
SET @Length = (@End - @Start) + 1
END
RETURN LTRIM(RTRIM(@HTMLText))
END
```

**Use of [scalar function](https://www.mindstick.com/forum/34598/how-to-create-scalar-function-in-sql):**

```
PRINT [dbo].[RemoveHtmlFronString]('<b> Hello</b>')
```

In above example I have created a [scalar function](https://www.mindstick.com/forum/34598/how-to-create-scalar-function-in-sql) that take a string type parameter.

It will remove all HTML tags from string and return plain text or string.

I hope it will help to after reading it.

\

---

Original Source: https://www.mindstick.com/articles/12998/what-is-scalar-function-in-sql

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
