Remove trailing zeros from a decimal column [closed] - sql

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
How can I remove the trailing zero from the below table using SQL:
SKU SIZE
ABC 35.000000
QWE 36.000000
RTY 37.000000
VGY 38.000000
Expected results:
SKU SIZE
ABC 35
QWE 36
RTY 37
VGY 38

In sql server cast the column containing decimal values to Int
Select SKU,CAST (Size AS INT)
From tablename
For MySql use integer division function DIV
SELECT SKU,Size DIV 1
From Tablename

I suggest
SELECT sku, int(size)
FROM tablename
It's less typing. ;-)

Related

Is there a way to convert numbers to circled numbers in Oracle SQL? ( 1 to ① or 20 to ⑳) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Looking for ways to convert numbers to characters.
For SqlServer (which you didn't specify)
SELECT NCHAR(numval+9311);
Explanation:
the "enclosed alphanumerics" are at Unicode codepoints 9312 ① through 9331 ⑳. A "numval" of 1 becomes 9312 before passing it to NCHAR
the NCHAR function converts from codepoint value to corresponding character
Warning:
This only works for values from 1 to 20 (there is no "circled number 21" and while there does exist a "circled digit zero" ⓪, that's at 9450)

SQL query to return only 11 digit numeric values [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Actual data:
|31345678921|
|56789056789|
|56780345678|
|4567 |
|3456 |
|00678596 |
|03456788453|
|ASA 2344 |
|34565 |
|BBq23 |
|DNF LIMIT |
Required data:
|31345678921|
|56789056789|
|56780345678|
|03456788453|
One method is:
where actual not like '%[^0-9]%' and
len(actual) = 11
That is, the value has no non-digits and is 11 digits long.
Another method is:
where try_convert(numeric(11,0), actual) between 10000000000 and 99999999999
That is, when converted to a numeric, the range suggests that it is 11 digits.
And a third method is:
where actual like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
SQL Server supports character classes with like, so you can just like [0-9] 11 times.

SQL extract multiple numeric values from string column [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I read and used the function suggested in this article:
http://blog.sqlauthority.com/2008/10/14/sql-server-get-numeric-value-from-alpha-numeric-string-udf-for-get-numeric-numbers-only/
and it works nice but actually I need the result in two columns (I'm expecting two numbers that should be seperated with spaces and / char in the original string)
Let's say "nfsdklj6 / 3 ddfsdf" should be 6 | 3
"nfsdklj45 / 100 ddfsdf" should be 45 | 100
I'm a rookie sql programmer, so any help or hint would be appreciated,
thanks
If you are using the mentioned udf
Declare #Table table (MyString varchar(25))
Insert into #Table (MyString) values
('nfsdklj6 / 3 ddfsdf'),
('nfsdklj45 / 100 ddfsdf')
Select *
,Val1=dbo.udf_GetNumeric(substring(MyString,1,charindex('/',MyString)))
,Val2=dbo.udf_GetNumeric(substring(MyString,charindex('/',MyString),50))
From #Table
Returns
MyString Val1 Val2
nfsdklj6 / 3 ddfsdf 6 3
nfsdklj45 / 100 ddfsdf 45 100
For your specific table
Select Shuma
,Val1=dbo.udf_GetNumeric(substring(Shuma,1,charindex('/',Shuma)))
,Val2=dbo.udf_GetNumeric(substring(Shuma,charindex('/',Shuma),50))
From [dbo],[Deals]
Where Shuma not like LIKE '%1 / 1%'

SQL Server 2000: how to replace a entry with only the last 2 characters [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a table in a SQL Server 2000 database with a column with several entries like 01-03, 04-05. The first 2 digits are the room number and the last two digits are the bed number.
I want to replace the 01-05, 03-07 etc. with only the bed number. So only the last two charcters have to be in the column.
How do I accomplish this?
Sample data is:
In the column [Bed] with values:
22-01
08-01
09-03
01-16
Result has to be:
01
01
03
16
RIGHT should solve your problem:
SELECT RIGHT(RTRIM(Bed), 2) FROM tbl

How to get avg between two values in SQL Server [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Please refer to the details shown here:
ID Value
---------
1 120
1 150
Query :
Select avg(value)
from table
group by Id
Current output = 130
Expected output =
120 + 150 / 2 = 135
Please let me know your comments.
SQL Server does integer arithmetic, even for integers. However, it doesn't round integers to the nearest 10. Perhaps on your real data, the following will do what you want:
Select avg(value * 1.0)
from table
group by Id ;
It changes the value to something with a decimal point, so the average is not an integer average.