Is there a function in Business Objects Web Intelligence (Version 2010) to test if a string contains a constant? I know the MATCH() function can be used to test a string for a pattern, similar to how SQL implements a LIKE condition.
For example:
myString = 'abc,def,ghi'
myString2 = 'def,ghi,jkl'
Both string variables above contain the constant 'def', but is there a function to test for this rather than using:
=IF(MATCH([Dimension];"def") OR MATCH([Dimension];"*def")
OR MATCH([Dimension];"def*") OR MATCH([Dimension];"*def*"))
//Do something
I have looked through the functions and formulas manual and haven't found what I was looking for, hence, here I am.
MATCH([Dimension];"*def*")) will produce the result you need. The wildcard will match the beginning of the string.
Alternatively, you can use Pos():
=Pos("def abc ghi";"def")
returns 1
=Pos("def abc ghi";"abc")
returns 5
=Pos("def abc ghi";"xyz")
returns 0
Related
I want to use LIKE operator in access 10 sql query with variable.
Example:
temporary variable var contains value bs
var = "bs"
I want to match every String that starts with value of temporary variable followed by zero or more numbers.
I am trying to fire the query:
select * from xyz where variety LIKE "#[tempvars]![var] + [0-9]*"
It is returning 0 records.
Thankz for the help.
You need to refer to your tempvar outside of the quotes, and use & for concatenation:
select * from xyz where variety LIKE "#" & [tempvars]![var] & "[0-9]*"
This will return all records where variety starts with a literal #, then whatever is in [tempvars]![var], then a number, and then any amount of characters.
You can check if that variety is available in your table or not. If that variety is available in your table then don't search with like operator and otherwise use like operator.
I am trying to build a query that will return different chars from different positions on a string. I'm using this query to get just the string i'll need from a bigger string:
MID(CStr(Movimento_Estoque_Cabecalho.Importados),1,(InStr(1,CStr(Movimento_Estoque_Cabecalho.Importados),"OD")-1))
With that i'm getting a string that looks like this:
OC0=35OC1=36
I need to get only what's after the = positions.
In this case would be 35,36
The Numbers returned after the = sign may vary from 1 to 999999.
Is that possible to do?
BTW, the database i'm using is MS-ACCESS 1997
I have a table called documents one of the fields is called location which shows the file path for the document. I need to change it from D:\........ to H:\.....
How can I do this using update in sql as the file paths vary in length and there are lots of records
You can use string helper function to achieve the same. Something like below
UPDATE documents SET location = 'H:' + Mid(location, 2, Len(location) - 2)
WHERE Left(location, 1) = 'D'
Here, Len() function returns the length of the string literal
Left() function returns 1 character from the left of the string literal
Mid() function give you substring from a string (starting at any position)
See MS Access: Functions for more information on the same.
I'm querying across two dbs separated by a legacy application. When the app encounters characters like, 'ü', '’', 'ó' they are replaced by a '?'.
So to match messages, I've been using a bunch of 'replace' calls like so:
(replace(replace(replace(replace(replace(replace(lower(substring([Content],1,153)) , '’', '?'),'ü','?'),'ó','?'), 'é','?'),'á','?'), 'ñ','?'))
Over a couple thousand records, this can (as you expect) is very slow. There is probably a better way to do this. Thanks for telling me what it is.
One thing you can do is implement a RegEx Replace function as a SQL assembly and call is as a user-defined function on your column instead of the Replace() calls. Could be faster. You also want to probably to the same RegEx Replace on your passed in query values.
TSQL Regular Expression
You could create a persisted computed column on the same table where the [Content] column is.
Alternatively, you can probably speed up the replace by creating a user defined function in C# using a StringBuilder. And you can even combine both of these solutions.
[SqlFunction(IsDeterministic = true, IsPrecise = true)]
public static SqlString LegacyReplace(SqlString value)
{
if(value.IsNull) return value;
string s = value.Value;
int l = Math.Min(s.Length, 153);
var sb = new StringBuilder(s, 0, l, l);
sb.Replace('’', '?');
sb.Replace('ü', '?');
// etc...
return new SqlString(sb.ToString());
}
Why not first do the same replace (chars to "?") on the string you are searching for in the app side using regular expressions? E.g. your SQL server query that was passed a raw string to search for and used these nested replace() calls will instead be passed a search string already containing "?"s by your app code.
Could you convert the strings to varbinary before comparing? Something like the below:
declare
#Test varbinary (100)
,#Test2 varbinary (100)
select
#Test = convert(varbinary(100),'abcu')
,#Test2 = convert(varbinary(100),'abcü')
select
case
when #Test <> #Test2 then 'NO MATCH'
else 'MATCH'
end
For example I have a column that contains string (in English - "A", "B" ) "AB1234" and I'd like to compare it to the string "AB1234" (in Russian "A", "B" ), for Example.
Is there any built-in function to achieve this?
The best way I found is to use Translate func where i enumerate all needed symbols.
You are looking for a function LOOKS LIKE.
Unfortunately there is no such function in SQL.
Instead, you can create a function-based index that casts every string to a common denominator using TRANSLATE, and search for the string:
CREATE INDEX ix_mytable_transliterate ON (TRANSLATE(UPPER(str), 'АВЕКМНОРСТУХ', 'AВEKMHOPCTYX'))
SELECT *
FROM mytable
WHERE TRANSLATE(UPPER(str), 'АВЕКМНОРСТУХ', 'AВEKMHOPCTYX') = TRANSLATE(UPPER('весна на танке'), 'АВЕКМНОРСТУХ', 'AВEKMHOPCTYX')