This question already has answers here:
Removing leading zeros from varchar sql developer
(5 answers)
Closed 4 years ago.
I have a string looks like this.
00000000004000000
00000000001100000
00000001432000000
00000000167700000
I want to remove all leading leading 0 from that column, how can I achieve that?
You can use the TRIM function:
SELECT TRIM(LEADING '0' FROM col)
this will work:
select ltrim(colname,'0') from table_name;
Related
This question already has answers here:
Turning a Comma Separated string into individual rows
(16 answers)
Closed 2 years ago.
NOIDEHOB_NOIDE1_4321-123
i want to create a querie that extract the following values from the example above:
NOIDEHOB
NOIDE1
4321-123
I need to base the query on the sign _. The values NOIDEHOB, NOIDE1 and 4321-123 are dynamic and the length will vary. There will never be any other _ sign in the string.
Any suggestions?
You can use string_split():
select s.value
from string_split('NOIDEHOB_NOIDE1_4321-123', '_') s
This question already has answers here:
Better techniques for trimming leading zeros in SQL Server?
(19 answers)
Closed 3 years ago.
How can I remove leading zeros from a string such as '0097619896'?
Numerical data types don't contain leading zeroes, so you can convert to a int/bigint/decimal/etc and it'll strip them off:
SELECT CONVERT(int,'0097619896'), CONVERT(decimal(10,0),'0097619896');
If the values aren't numerical values, you can use PATINDEX to find the first non-zero character and STUFF to remove them:
SELECT STUFF(V.YourString,1,PATINDEX('%[^0]%',V.YourString)-1,'')
FROM (VALUES('0097619896-abc'))V(YourString);
This question already has answers here:
Split string and take last element
(15 answers)
Closed 6 years ago.
i have a string like that $TAOVV*NK_LFE_11029_41586 and i want to select only 11029, the number between _. I try with
substring([OrderCode],PatIndex('%_[0-9]_%', [OrderCode]),LEN([OrderCode]))
but not extract only that number.How i can define the length that change and it's not always of 5 characters as in this example?
You need to do the substring twice..
Try with this
declare #code nvarchar(100)='$TAOVV*NK_LFE_11029_41586'
select substring(substring(#code,PatIndex('%_[0-9]_%', #code)+1,LEN(#code)),1,charindex('_',substring(#code,PatIndex('%_[0-9]_%', #code)+1,LEN(#code)))-1)
This question already has answers here:
removing characters from field in MS Access database table
(4 answers)
Closed 8 years ago.
I have table with data like
samcol
60.78686
46.0000
45.43240
56.3453450
And i'm trying to remove '.' before decimal places. And table should looks like
samcol
6078686
460000
4543240
563453450
Use Replace String function to replace all the . with empty string
Select Replace(samcol,'.','') from yourtable
This question already has answers here:
Oracle trim whitespace on the inside of a string
(2 answers)
Closed 8 years ago.
I need to remove all spaces from column values of varchar2 type in an Oracle table.
For example, 2012_2 psk should become 2012_2psk.
I've tried to use REPLACE(column_name, ' ', '') but it doesn't work.
Can anyone help me?
I've found the solution. There are not white spaces, there are some other symbols that show themselves as blank spaces. So next code is working fine:
SELECT regexp_replace(docnum, '\W','') FROM tmp_uploadtable;
Please try:
regexp_replace(column_name, '[[:space:]]*','')
SQL Fiddle Demo