This question already has answers here:
How to get only numeric column values?
(5 answers)
Closed 8 years ago.
I'm hoping that there is some basic string function which will do this that I just haven't found yet.
Specifically for scenarios where length of the string is unknown:
Is there a succinct method of telling if a string variable only contains [0-9] values?
For example, the following method works but require additional mention of all possible characters that would appear other than numerals.
SELECT VAR
FROM #TABLE1
WHERE VAR NOT LIKE '%[A-Z]%'
and
SELECT VAR
FROM #TABLE1
WHERE VAR LIKE '[0-9][0-9][0-9][0-9][0-9]...'
doesn't work because the length of the VAR is required for this filter.
Thanks in advance
SELECT VAR FROM #TABLE1
WHERE VAR NOT LIKE '%[^0-9]%'
Related
This question already has answers here:
PostgreSQL substring get string between brackets
(2 answers)
Closed 1 year ago.
I have the following details column, with varying parameters. How can I get only joblib values? "The Place of joblib is not always the same, so I may bot be able to use substring count"
date:01/12/2014--**--joblib:[snbsd]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
date:01/12/2014--**--joblib:[jinxthin]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
date:01/12/2014--**--joblib:[snbserv]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
date:01/12/2016--**--joblib:[sql12server]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
date:01/12/2015--**--joblib:[stfmbinserx]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
date:01/12/2011--**--joblib:[ftplikes]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto
Desired result:
snbsd
jinxthin
snbserv
sql12server
stfmbinserx
ftplikes
Here You go:
substring(substring(var1, position('joblib:' in var1)+8), 1, position(']' in substring(var1, position('joblib:' in var1)+8))-1)
replace var1 with column name containing Your string
With below You can try it out directly on PostgreSQL:
WITH myconstants (var1) as (
values ('date:01/12/2014--**--joblib:[snbsd]--**--date_type:no_date--**--max_feat_values:ss,group_filters:[]--**--no_imp_phrases:1--**--variable_facets:auto')
)
SELECT substring(substring(var1, position('joblib:' in var1)+8), 1, position(']' in substring(var1, position('joblib:' in var1)+8))-1)
FROM myconstants
This question already has answers here:
How to deal with semantic version data type in BigQuery
(2 answers)
Closed 1 year ago.
I need to convert a column of type string to float so that I could perform mathematical calculations like >, <, = etc on it. I tried SAFE_CAST, but it results nothing. Could anyone please help in solving this.
What I have:
column (TYPE STRING)
11.2.1
11.66.3
2.56.4
11.67.7
What I need:
column (TYPE FLOAT64)
11.2.1
11.66.3
2.56.4
11.67.7
I need this conversion mainly to perform mathematical comparison.
If these are essentially nested version numbers, then one approach is to normalize the values in the string so they are zero-padded. Then regular comparisons work.
Assuming four digits is sufficient for each number, you can use:
select (select string_agg(lpad(cast(el as string), 4, '0'), '.')
from unnest(split(t.val, '.')) el
) str
from (select '11.2.1' as val union all select '11.67.7') t
This question already has answers here:
MySQL variable format for a "NOT IN" list of values
(3 answers)
Closed 6 years ago.
This value is in a column in a table:
'962091','962092','962093'
I try to use this in a where. First I declare a variable:
DECLARE #KPLnr varchar(100)
SET #KPLnr = CONVERT(nvarchar(max), dbo.UF_GetOption('FastecKPL')) /* here I get the values in */
If I select, I get the correct values of #KPLnr: '962091', '962092','962093', but if I try to use it in a where statement, it seems like the value is set wrong.
I get 0 results, but if I set it manually with:
WHERE c.kpl IN ('962091', '962092','962093')
I got 414 results.
So why is WHERE c.kpl IN ('962091', '962092', '962093') not equal to
WHERE c.kpl IN (#KPLnr) in my code?
When an apostrophe is stored in a text column, you need to escape it by adding an extra apostrophe:
WHERE c.kpl IN ('962091'', ''962092'',''962093')
This question already has answers here:
T-SQL: How to use parameters in dynamic SQL?
(4 answers)
how to pass variables this in dynamic query in sql
(1 answer)
Closed 7 years ago.
I have a series of datetime variables that need to be referenced, and the key to which variable needs referencing is reached by using substring on another field. I can create the name of the variable as a string using string manipulation, something like this:
'#' + SUBSTRING(field, CHARINDEX(',', field) + 2, LEN(field) - CHARINDEX(',', field) + 1) + 'start'
Is there a way to get SQL to recognize that this is the name of one of my variables? Some kind of function to convert the string?
This question already has answers here:
Equals(=) vs. LIKE
(16 answers)
WHERE clause on SQL Server "Text" data type
(7 answers)
Closed 7 years ago.
what is the differences between = to like ?
thanks for help :)
by the way if it's help , the error i get is: the data types text and varchar are incompatible in the equal to operator [msg 402]
1:
Like
The LIKE operator is used to search for a specified pattern in a column.
Where
The WHERE clause is used to extract only those records that fulfill a specified criterion.
In your case the first query do not work is because no records match the criteria you are searching.