'Data types to store Integer and Float values in SQL Server
What would be the best data type for storing Integer, Float values altogether in SQL Server.
I need to store normal integer and point (float) decimal values in a single column.
Ex.
ColumnNameValues
15
15.5
12.3
17
19.8
Solution 1:[1]
The best data type for storing Integer, Float values altogether in MySQL is : FLOAT
Solution 2:[2]
If you dont need to see the floats correctly in the DB, you could convert the 4 bytes of the float into an integer and store it as an integer. If you want to get it back, read it from the DB then convert it to the float again.
If you dont have the information from the context, if the stored value is an integer or float, it gets a little tricky, you would need to limit the integers or floats somehow, e.g. "sacrifice" one bit to identify, which variation it is.
Solution 3:[3]
if you are going to store in integer it will cut down the values after .(point)but if you going to use Float it will enter all the values whether it is int or float
declare @t table (ID float)
insert into @t(id)values (15) ,(15.5),( 12.3),( 17),( 19.8)
select * from @t
declare @t table (ID int)
insert into @t(id)values (15) ,(15.5),( 12.3),( 17),( 19.8)
select * from @t
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Avenger0815 |
| Solution 3 | paul |
