How To Convert Numeric Values to Integers in MS SQL Server?
Submitted by: AdministratorSometimes you need to round a numeric value into an integer. SQL Server 2005 offers you a number of ways to do this:
* FLOOR(value) - Returning the largest integer less than or equal to the input value. The returning data type is the same as the input value.
* CEILLING(value) - Returning the smallest integer greater than or equal to the input value. The returning data type is the same as the input value.
* ROUND(value, 0, 0) - Returning the integer most close to the input value. The returning data type is the same as the input value.
* CAST(value AS INT) - Returning the largest integer less than or equal to the input value. The returning data type is INT.
* CONVERT(INT, value) - Returning the largest integer less than or equal to the input value. The returning data type is INT.
The tutorial exercise below gives some good examples of converting numeric values to integers:
<pre> SELECT FLOOR(1234.5678);
SELECT CEILING(1234.5678);
SELECT ROUND(1234.5678, 0, 0);
SELECT CAST(1234.5678 AS INT);
SELECT CONVERT(INT, 1234.5678);
GO
1234
1235
1235.0000
1234
1234</pre>
Submitted by: Administrator
* FLOOR(value) - Returning the largest integer less than or equal to the input value. The returning data type is the same as the input value.
* CEILLING(value) - Returning the smallest integer greater than or equal to the input value. The returning data type is the same as the input value.
* ROUND(value, 0, 0) - Returning the integer most close to the input value. The returning data type is the same as the input value.
* CAST(value AS INT) - Returning the largest integer less than or equal to the input value. The returning data type is INT.
* CONVERT(INT, value) - Returning the largest integer less than or equal to the input value. The returning data type is INT.
The tutorial exercise below gives some good examples of converting numeric values to integers:
<pre> SELECT FLOOR(1234.5678);
SELECT CEILING(1234.5678);
SELECT ROUND(1234.5678, 0, 0);
SELECT CAST(1234.5678 AS INT);
SELECT CONVERT(INT, 1234.5678);
GO
1234
1235
1235.0000
1234
1234</pre>
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | How To Start SQL Server Browser Service? |
☺ | How to download Microsoft SQL Server 2005 Express Edition? |
☺ | How To Execute the Cursor Queries with "OPEN" Statements? |
☺ | What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |