Hex values in SQL Database - converting to decimal - sql

I am working with a SQL database that contains a column of numbers in hex. The numbers are entered into a third party application as a decimal and are saved in the SQL database as a hex value. Only issue is I can't figure out how the hex values correspond to the decimal values.
Example:
0x000000000032000000 is 50
0x0000000000E9030000 is 1001
0x00000000002C010000 is 300
Any help is much appreciated.

Try using a CONVERT
SELECT CONVERT(INT, 0xFFFFFF)

Related

SQL convert nvarchar into decimal dynamic rows

I am not so familiar with using convert in SQL so thats why i am stuck with the following situation:
The column has a nvarchar(max) and i would like to convert it into decimal (18,2). But there are some rows that consist a "full" amount (see red box). For all values with the full amount i would like to have it as 1222,00
When creating a SQL view I got this error:
Error converting data type nvarchar to numeric.
How can i still convert this column into decimal?
Many thanks
From your pictures it seems to me like you are using SQL-Server. If so your problem is having , as decimal point instead of . It has nothing to do with having whole and decimal numbers in your data.
So you should replace it before converting data.
SELECT CONVERT(decimal(18,2), REPLACE(ColumnName,',','.')) FROM TableName
DB<>fiddle

Display money with decimal in sql server 2008

I am having some number in DB table column, i have written stored procedure to format that number. The requirement is i need to display the number with comma and decimal points. I have tried below, but only comma is coming.. any solutions,
PARSENAME(CONVERT(VARCHAR,CAST(TotalAmount/1000 as MONEY),1),2)
Actual result: 1,134
Expected result: 1,134.0
I want to do this in SQL server itself.
You can accomplish currency formatting as:
SELECT CONVERT(varchar, CAST(5555 AS money), 1)
but i would suggest doing such formatting on the front end, not on the data side

How to format decimal output in sql server select?

In my tables I have columns that is decimal (16,5). When I do
SELECT WorkHours, BillHours
FROM Hours
It gives me be that result:
2.00000 1.00000
2.00500 1.05000
How I can get back this numbers in nice looking format:
2 1
2.005 1.05
You can use ROUND() function in SQL SERVER.
However, all values in one column will have same number of decimal places.
If you want to format it further, consider client side formatting instead of writing custom server side code.

Database Data Types

What database data type do I need to use to store a numerical value with 18 digits after the decimal place? I've tried double and float but it doesn't work it only shows 16 digits after the decimal place. I'm using MS SQL Server 2005 and 2008.
Assuming your values are not too big, you want to use DECIMAL. Something like DECIMAL(20, 18) (adjust the first value for the total number of digits in the number).
You can read about it here.

Write Decimal numbers in SQL 2008

In need to write the number 7.2 in a table field.
What type the field needs to be.
And what type needs the variable to be?
SQL Server 2008 has a DECIMAL type which works quite well.
You can define a precision (total number of digits) and a scale (number of digits after the decimal separator).
DECIMAL(2,1) would be: two digits, one of which after the separator (one before)
DECIMAL(5,2) would be: five figits total, two of which after the separator (three before)
See DECIMAL and NUMERIC in SQL Server Books Online for more details
In .NET, this would be a type decimal as well.