Remove brackets from sql query result - netlogo

I have executed a simple MySQL query in NetLogo. But result returns in double square brackets such as [[472]]. How can I remove them? I tried using string length with 'length' command and removing first two and last two characters. But, size of the result returns as 1 which is expected as 7.
set query "select max(x) from colorinfo"
set width (mysql:executeQuery db query)

Related

REGEXP_LIKE QUERY IN ORACLE DB

I need to currently match 00000012345 and 12345 in my DB search query.
I am currently using following query:
SELECT *
FROM BPP.CHECK_REGISTER
WHERE CHECK_NO like CONCAT('%',:checkNum)
for searching but here % can mean any character other than 0 hence I have replaced this query with following:
SELECT *
FROM BPP.CHECK_REGISTER
WHERE REGEXP_LIKE (CHECK_NO,'^(0*12345)$')
but in this query I don't want to mention 12345 but mention it as a user entered parameter like the first query :checkNum
How do I rephrase the REGEXP_LIKE condition with only 2 arguments with user input :checkNum as oracle db allows only a maximum of 2 arguments. (another problem)
You can concatenate the parameter:
SELECT *
FROM BPP.CHECK_REGISTER
WHERE REGEXP_LIKE (CHECK_NO,'^(0*'||:checkNum||')$');
Alternatively add the regex part to the user entered value (in your application code) before passing it to the query.

OrientDB COALESCE Function With Unexpected Results

Using OrientDB 2.1.2, I was trying to use the inherent COALESCE functionality and ran into some strange results.
Goal: select the maximum value of a property based on certain conditions OR 0 if there is no value for that property given the conditions.
Here's what I tried to use to produce my results.
Attempt 1: Just selecting the Maximum value of a property based on some condition - This worked as I expected... a single result
Attempt 2: Same query as before but now I'm adding an extra condition that I know will cause no results to be returned - This also worked as I expected... no results found
Attempt 3: Using COALESCE to select 0 if the result from the second query returns no results - This is where the query fails (see below).
I would expect the result from the second query to return no results, thereby qualifying as a "NULL" result meaning that the COALESCE function should then go on to return 0. What happens instead is that the COALESCE function is seeing the results of the inner select (which again, returns no results) as a valid non-null value, causing the COALESCE function to never return the intended "0" value.
Two questions for those who are familiar with using the OrientDB API:
Do you think this functionality is working properly or should an issue be filed with the orientdb issue tracker?
Is there another way to achieve my goal without using COALESCE or by using COALESCE in a different way?
Try rather:
select coalesce($a, 0) from ... let $a = (subquery) where ...
Or also this variant because the sub-select returns a result set, but the coalescence wants a single value:
select coalesce($a[0], 0) from ... let $a = (subquery) where ...

SQL Server Doesn't Find Record Containing Float Value That It Returned

I have a query similar to this:
SELECT SpecimenID, TestPeriodID, Grams, ConsumptionRate FROM LabData
WHERE TestPeriodID = 255
AND TestID = 1
AND Grams = 728560
The record that is returned has a value of 16.5667068820687 for the FLOAT column ConsumptionRate.
I now add the following to the end of my query:
AND ConsumptionRate = 16.5667068820687
Executing the new query returns zero records, even though the additional criteria are exactly what SQL Server itself reported. I assume that this is a rounding error. However, I have a CLR function that is executing the 2nd query based on the results returned by the first.
What can I do to in my generated search criteria to maintain an accurate representation of the first result, but not miss existing records in the second result?
How about if you use - does it bring any result?
ConsumptionRate > 16.56 AND ConsumptionRate < 16.57

How to handle unusual characters in tsql

In SSMS I query for a record by ID, then copy/paste a specific value from the results grid into a new query to search for that specific value and no records are found.
The field is nvarchar & the value in question has an alpha sign, but I don't see why that should cause a problem.
Use:
where ChemicalFormHtml = N'...'

Nhibernate Expression.In limit

I am querying the Nhibernate criteria query with more then 2100 values for In clause.
I do something like Session.CreateCriteria(typeof()).Add(Expression.In("fieldName",arrayValue))
Where arrayValue contains more then 2100 values. I face error
Exception occurred:
UnknownError
NHibernate.ADOException: could not execute query ..then the query with more then 3000 values in array.
with some google help we found out that IN clause in Sql supports only till 2100 values.
Does anyone has faced similar issue earlier? We do not want to change the query as it is written in some generic way and not customized one.
This is a limitation of SQL Server. I wouldn't suggest doing this, but if you insist, you could work around it by creating a table-value sql function (see http://www.dzone.com/snippets/function-getting-comma) that splits up a string by commas (or whatever delimiter you want) and returns the values as a table, and then pass in all your ID's as (say) a comma separated list in 1 parameter and use a SQLCriterion in your criteria query.
eg:
criteria.Add(
new SQLCriterion("{alias}.ID IN (SELECT element FROM dbo.GetCSVValues(?))",
new[]{csvListOfIds},
new[]{NHibernateUtil.String}))
You could split the array into multiple batches, query multiple times, and then combine the result.