HI I was wondering If we could use SOQL statements using LIKE on Identities like:
select Id,Name from Account where Id not LIKE '001W%' limit 10
So if there were ID strings that start with those 4 characters I can skip those and get 10 that are different. I tried but I get an exception indicating that I have an 'unexpected token'.
Thanks
According to the salesforce documentation:
The LIKE operator is supported for string fields only.
Related
I have a column workId in my table which has values like :
W1/2009/12345, G2/2018/2345
Now a user want to get this particular id G2/2018/2345. I am using like operator in my query as below:
select * from u_table as s where s.workId like '%2345%' .
It is giving me both above mentioned workids. I tried following query:
select * from u_table as s where s.workId like '%2345%' and s.workId not like '_2345'
This query also giving me same result.
If anyone please provide me with the correct query. Thanks!
Why not use the existing delimiters to match with your criteria?
select *
from u_table
where concat('/', workId, '/') like concat('%/', '2345', '/%');
Ideally of course your 3 separate values would be 3 separate columns; delimiting multiple values in a single column goes against first-normal form and prevents the optimizer from performing an efficient index seek, forcing a scan of all rows every time, hurting performance and concurrency.
Using the camel sql component seems like a good thing in a project using camel. But i dont see the point for cases when dynamic sql is needed. Use case :
on front end user can
select a type of record only and submit search, in this case where clause is : "from table1 where col1 = valueX1"
also select a date range for offer start date so then where clause looks like "from table1 where col1 = valueX1 and dateCol between (...)"
and so on for other UI if values are given total of 10 different columns, in different combinations
I tried to use a dynamic sql figured out three choices:
1. using a receipient list so route is selected at run time, seemed over kill.
2. using the body as a sql and using the useMessageBodyForSql=true
3. using a custom prepareStatementStrategy
For 2 and 3 i was not able to send parameter names or specify headers or properties to be part of values to be used in Prepared statement.
For .2. had to give the sql like :
select c1, c2 ... from t1 where x = ? and y = ?
and then a java util list with the values in order.
So - is there any advantage to using this? Any feature of the sql component that makes it better to use than to directly use the spring jdbc template that it uses?
I would suggest to use Camel Templating to make the statements dynamic like that:
to("freemarker://sql/template.ftl")
.log("${body}")
.to("sql:ignored?useMessageBodyForSql=true");
Note that query parameters are represented by a ? instead of a # symbol if the statement comes from the body:
-- sql/template.ftl
select count(*) as count
from a_table
<#if headers.namePattern?has_content>
where name like :?namePattern
</#if>
You might also switch to the MyBatis component which supports advanced templating via MyBatis but this comes with a much higher overhead in terms of coding and configuration.
Im using influxDb and recording user visits to a dictionary pages and trying to get some queries working.
Like for example I'm trying to find out how to get a sorted set of headwords sorted by a number of visits to a particular word definition within some timeframe. So basically words sorted by a number of visits.
Im trying something like this:
SELECT COUNT(*) FROM lookup GROUP BY word ORDER BY count_value LIMIT 100
^But it doesn't work. Error message is "Server returned error: error parsing query: only ORDER BY time supported at this time".
Is what im trying to do not achievable in influxDb?
As noted by the error that was returned
Server returned error: error parsing query: only ORDER BY time supported at this time
InfluxDB only supports ORDER BY time at the moment. To achieve the result that you're looking for you'd need to do the ORDER BY client side.
In my query (the database is a sql server) I use a RegEx for a select command like this:
SELECT * FROM test WHERE id LIKE '1[2,3]'
(This query is tested and returns the data I want)
I want to use a paramter for this RegEx. For that I definded the Paramter in iReport $P{id} as a string and the value is "1[2,3]".
In my query I use now this parameter like this:
SELECT * FROM test WHERE id LIKE $P{id}
As result I get a blank page. I think the problem is that the value of the parameter is defined with " ". But with ' ' I get a compiler error that the paramter isn't a string.
I hope someone can help me.
LIKE applies to text values, not to numeric values. Since id is numeric use something like this:
SELECT * FROM test WHERE id IN (12, 13)
with the parameter
SELECT * FROM test WHERE id IN ($P!{id_list})
and supply a comma separated list of ids for the parameter. The bang (!) makes sure that the parameter will be inserted as-is, without string delimiters.
Btw: LIKE (Transact-SQL) uses wildcards, not regex.
You can still use LIKE since there exists an implicit conversion from numeric types to text in T-SQL, but this will result in a (table or index) scan, where as the IN clause can take advantage of indexes.
The accepted answer works but it is using String replacement, read more about sql-injection, to understand why this is not good practice.
The correct way to execute this IN query in jasper report (using prepared statement) is:
SELECT * FROM test WHERE $X{IN, id, id_list}
For more information as the use of NOTIN, BETWEEN ecc. see JasperReports sample reference for query
I'm trying to make adjustments to this LDAP query so that any employeeIDs that contain only numbers are included in the filter and anything else is skipped. (!employeeID=\00)will grab any ID that is not blank or null I believe, but how do I test for alpha or just numeric characters in AD? Thanks
-LdapFilter "(&(&(objectCategory=person)(objectClass=user)
(!userAccountControl:1.2.840.113556.1.4.803:=2))(&(objectCategory=person)(objectClass=user)
(!objectClass=inetOrgPerson))(sAMAccountName=s0*)(!sAMAccountName=*-d)(!sAMAccountName=*-e)
(!sAMAccountName=*-a)(!Name=Test*)(!Name=v-*)(!employeeID=\00))”
I don't think we can use the search filter to filter out non-digit values.
Found no related filters here:
http://msdn.microsoft.com/en-us/library/aa746475%28v=vs.85%29.aspx
Instead you may use a simpler filter to get all users, add those attributes (e.g. employeeID, sAMAccountName, etc.) to the properties-to-load list. And then filter that on client side.
Besides, filter like attr=*sth will be slow. The index only helps in equal (attr=sth) and start-with (attr=sth*) ones.