---
title: "why an int datatype variable accept a string format value in stored procedure in SQL Server."  
description: "why an int datatype variable accept a string format value in stored procedure in SQL Server."  
author: "Ravi Vishwakarma"  
published: 2021-10-13  
updated: 2021-10-13  
canonical: https://www.mindstick.com/forum/156783/why-an-int-datatype-variable-accept-a-string-format-value-in-stored-procedure-in-sql-server  
category: "mssql server"  
tags: ["sql server"]  
reading_time: 2 minutes  

---

# why an int datatype variable accept a string format value in stored procedure in SQL Server.

Why does an [integer](https://answers.mindstick.com/qa/113667/write-code-for-roman-to-integer) [datatype](https://www.mindstick.com/forum/160266/explain-the-datatype-data-annotation-and-its-significance-in-data-entry-and-display) [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) accept a [string value](https://www.mindstick.com/forum/159623/how-to-get-an-enum-value-from-a-string-value-in-c-sharp) in a stored [procedure in SQL](https://www.mindstick.com/forum/158350/what-is-a-stored-procedure-in-sql-server-and-how-to-create-one) [Server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over)? How to solve it?

## Replies

### Reply by Ashutosh Kumar Verma

**Passing a number in [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) format to an integer variable in a [stored procedure](https://www.mindstick.com/articles/803/using-stored-procedure-in-asp-dot-net) :**

When pass a value to integer datatype variable in the form of string value then that accept it because after accept first that value is implicitly CAST to an integer then the value is assigning to the parameter.

Ex- If we pass an integer value as ' 145 ' to integer type parameter then it implicitly CAST to an integer type value successfully in 145 then it assigned to the parameter of stored procedure then the statement is work file.

I have create a Stored Procedure with two parameters,

```
    create procedure sp_Demo(@ID int,@Name varchar(255))AS --SQL Statement
```

We pass Value to parameter of above stored procedure like-

```
EXEC sp_Demo@ID=145,@Name=' Radhe Krishna ' ;
```

The above procedure work file.

If we pass the value ' 145' instead of 145 to @ID parameter and ' Radhe Krishna ' to @Name parameter then also that procedure execute fine because before accepting the value to parameter that value will CAST first to the parameters datatype then assign to the parameters so stored procedure work fine and execute.

**Note** - CAST is function to convert one datatype value in other datatype value. CONVERT() is also used for same purpose.


---

Original Source: https://www.mindstick.com/forum/156783/why-an-int-datatype-variable-accept-a-string-format-value-in-stored-procedure-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
