The following query is not working in route query:
$body.Weather.Temperature in ['30','50']
I checked the documentation and the syntax looks right.
IN and NIN (not in) operator it used to check the item is or isn't in the array constants like ['wired', 'wifi'].
For your case, you need use Comparison operator: >= and <= like this:
$body.Weather.Temperature >= 30 AND $body.Weather.Temperature <= 50
For detailed information you can reference "IoT Hub query language for device twins, jobs, and message routing".
Update:
For selecting the exact value 30/50 you can use the following query string as a workaround.
$body.Weather.Temperature = 30 OR $body.Weather.Temperature = 50
Related
I have a matrix in ssrs2008 like below:
GroupName Zone CompletedVolume
Cancer 1 7
Tunnel 1 10
Surgery 1 64
ComplatedVolume value is coming by a specific expression <<expr>>, which is equal to: [Max(CVolume)]
This matrix is filled by a stored procedure that I am not supposed to change if possible. What I need to do is that not to show the data whose CompletedVolume is <= 50. I tried to go to tablix properties and add a filter like [Max(Q9Volume)] >= 50, but when I try to run the report it says that aggregate functions cannot be used in dataset filters or data region filters. How can I fix this as easy as possible?
Note that adding a where clause in sql query would not solve this issue since there are many other tables use the same SP and they need the data where CompletedVolume <= 50. Any help would be appreciated.
EDIT: I am trying to have the max(Q9Volume) value on SP, but something happening I have never seen before. The query is like:
Select r.* from (select * from results1 union select * from results2) r
left outer join procedures p on r.pid = p.id
The interesting this is there are some columns I see that does not included by neither results1/results2 nor procedures tables when I run the query. For example, there is no column like Q9Volume in the tables (result1, result2 and procedures), however when I run the query I see the columns on the output! How is that possible?
You can set the Row hidden property to True when [Max(CVolume)] is less or equal than 50.
Select the row and go to Row Visibility
Select Show or Hide based on an expression option and use this expression:
=IIF(
Max(Fields!Q9Volume.Value)<=50,
True,False
)
It will show something like this:
Note maximum value for Cancer and Tunnel are 7 and 10 respectively, so
they will be hidden if you apply the above expression.
Let me know if this helps.
After I run an async task
tasks.add.apply_async( (10, 10))
I checked the result backends database table celery_taskmeta and noticed the result containing something like gAJLBC4=
I couldn't find in the docs what that result implies and whether I can store the actual result of the function call ( ie, the return value ) in the table as is.
For this instance where I am executing a task which adds two numbers : 10 and 10 , the result column in celery_taskmeta should have 20 as per my understanding ( which is probably wrong ) .
How should I achieve that ?
I'm assuming that result is also serialized? I'm using a redis broker and not clear which configuration I need to set to be able to retrieve the actual return value.
the best way to get the result is not to query the database directly and instead to use the result api
result = tasks.add.apply_async( (10, 10))
result.ready
> True
result.result
> 20
I've been trying to modify and input the following the query from an Access database into a SQL Server database but keep getting errors, e.g. "int is not a recognised built in function name".
Any way around this?
SELECT Tasks.Task_id,
Days_1.next_working_day AS Day_date
FROM Intervals
INNER JOIN ((Days INNER JOIN Days AS Days_1 ON Days.day_of_week = Days_1.day_of_week)
INNER JOIN Tasks ON Days.Day_date = Tasks.Start_date)
ON Intervals.Interval_id = Tasks.Interval_id
WHERE (((Days_1.next_working_day)>=[tasks].[start_date])
AND
((Intervals.Interval_Type_Name)="Fortnightly")
AND
((DateDiff("d",[tasks].[start_date],[days_1].[day_date])/14-int(DateDiff("d",[tasks].[start_date],[days_1].[day_date])/14)<>0)=0))
ORDER BY Days_1.next_working_day;
Thanks!
The culprit is in your WHERE clause:
... -int(DateDiff("d",[tasks].[start_date],[days_1].[day_date])/14)
...which is not valid out of the box (no such built-in function exists). Presumably you're trying to do some rounding with a cast. See CAST and CONVERT for T-SQL. You might also want to look into functions CEILING and FLOOR. I would be remiss if I didn't suggest revisiting that logic for what you're trying to do.
Regarding the query itself, I gave your WHERE clause a second look. As Gordon Linoff points out, what <>0)=0) is there for is unclear and is going to be the next error you run into. It looks like maybe the original query intended on extracting 2 week intervals in their entirety in a roundabout way. If so, then my best guess as to what that part of the clause should look like is:
(
DateDiff("d", [tasks].[start_date], [days_1].[day_date]) / 14.0 -
DateDiff("d", [tasks].[start_date], [days_1].[day_date]) / 14
= 0
)
Note now the division by 14.0 and not on the 2nd calculation which will always return an int because of integer division (so that cast becomes unnecessary).
Better yet, use modulo:
(
DateDiff("d", [tasks].[start_date], [days_1].[daydate]) % 14 = 0
)
I really am not sure if this is what you're going after but it's my best guess without more information.
I have a text field (field named "BiographyText" in the "Employs" table) in SQL Server 2008 which stores KPI target figures:
rebfirst60,
reifirst1.3,
retfirst50
The first target is 60, for RebFirst, the second is 1.3 for ReiFirst and 50 for the third, RetFirst.
I want to be able to return the 3 different numerical values, as these would be deemed the targets for each kpi for a certain employee.
I am having a complete mind block trying to figure out the best way to do this, any advice/help?
Overall I am trying to find the kpiname ("rebfirst") and then retrieve the next 2 characters/digits
I tried the following, but it errors on function 2 of the first substring, as it is non-numeric:
select SUBSTRING(biographytext,SUBSTRING('rebfirst',1,2),2) from employs
Thanks
Try this
SELECT
CASE WHEN PatIndex('%[a-z]%',REVERSE(BiographyText)) > 0
THEN RIGHT(BiographyText,PatIndex('%[a-z]%',REVERSE(BiographyText))-1)
ELSE '' END AS target
FROM employs
and also check another solution using function
From Post The first target is 60, for RebFirst, the second is 1.3 for ReiFirst and 50 for the third, RetFirst.
From Comment I don't need the actual kpiname from this just the value
The following Query will give you the Answer.
select case column_name when 'rebfirst60' then 60
when 'reifirst1.3' then 1.3
when 'retfirst50' then 50
from employs
I have this now by using the following:
select
SUBSTRING(SUBSTRING(biographytext,1,10),9,2) as RebookingFirst,
SUBSTRING(SUBSTRING(biographytext,11,20),12,3) as ReInventFirst,
SUBSTRING(SUBSTRING(biographytext,21,30),16,3) as ReCreateFirst,
SUBSTRING(SUBSTRING(biographytext,31,40),20,2) as RetentionFirst,
SUBSTRING(SUBSTRING(biographytext,41,50),23,2) as ReferralsFirst
from employs
This gives me the results for each kpi
I’ve read that logical operator AND has higher order of precedence than logical operator IN, but that doesn’t make sense since if that was true, then wouldn’t in the following statement the AND condition got evaluated before the IN condition ( thus before IN operator would be able to check whether Released field equals to any of the values specified within parentheses ?
SELECT Song, Released, Rating
FROM Songs
WHERE
Released IN (1967, 1977, 1987)
AND
SongName = ’WTTJ’
thanx
EDIT:
Egrunin and ig0774, I’ve checked it and unless I totally misunderstood your posts, it seems that
WHERE x > 0 AND x < 10 OR special_case = 1
is indeed the the same as
WHERE (x > 0 AND x < 10) OR special_case = 1
Namely, I did the the following three queries
SELECT *
FROM Songs
WHERE AvailableOnCD='N' AND Released > 2000 OR Released = 1989
SELECT *
FROM Songs
WHERE (AvailableOnCD='N' AND Released > 2000) OR Released = 1989
SELECT *
FROM Songs
WHERE AvailableOnCD='N' AND (Released > 2000 OR Released = 1989)
and as it turns out the following two queries produce the same result:
SELECT *
FROM Songs
WHERE AvailableOnCD='N' AND Released > 2000 OR Released = 1989
SELECT *
FROM Songs
WHERE (AvailableOnCD='N' AND Released > 2000) OR Released = 1989
while
SELECT *
FROM Songs
WHERE AvailableOnCD='N' AND (Released > 2000 OR Released = 1989)
gives a different result
I'm going to assume you're using SQL Server, as in SQL Server AND has a higher order of precedence than IN. So, yes, the AND is evaluated first, but the rule for evaluating AND, is to check the expression on the left (in your sample, the IN part) and, if that is true, the expression on the right. In short, the AND clause is evaluated first, but the IN clause is evaluated as part of the AND evaluation.
It may be simpler to understand the order of precedence here as referring to how the statement is parsed, rather than how it is executed (even if MS's documentation equivocates on this).
Edit in response to comment from the OP:
I'm not all together certain that IN being classified as a logical operator is not specific to SQL Server. I've never read the ISO standard, but I would note that the MySQL and Oracle docs define IN as a comparison operator, Postgres as a subquery expression, and Sybase itself as a "list operator". In my view, Sybase is the nearest to the mark here since the expression a IN (...) asks whether the value of attribute a is an element of the list of items between the parentheses.
That said, I might imagine the reason that SQL Server chose to classify IN as a logical operator is two-fold:
IN and the like do not have the type restrictions of the SQL Server comparison operators (=, !=, etc. cannot apply to text, ntext or image types; IN and other subset operators can be used against any type, except, in strict ISO SQL, NULL)
The result of an IN, etc. operation is a boolean value just like the other "logical operators"
Again, to my mind, this is not a sensible classification, but it is what Microsoft chose. Maybe someone else has further insight into why they may have so decided?
Call me a n00b, but I always use parentheses in nontrivial compound conditions.
SELECT Song, Released, Rating
FROM Songs
WHERE
(Released IN (1967, 1977, 1987))
AND
SongName = ’WTTJ’
Edited (Corrected, the point remains the same.)
Just yesterday I got caught by this. Started with working code:
WHERE x < 0 or x > 10
Changed it in haste:
WHERE x < 0 or x > 10 AND special_case = 1
Broke, because this is what I wanted:
WHERE (x < 0 or x > 10) AND special_case = 1
But this is what I got:
WHERE x < 0 or (x > 10 AND special_case = 1)
In Mysql at least, it has a lower precedence. See http://dev.mysql.com/doc/refman/5.0/en/operator-precedence.html
I think of IN is a comparison operator whereas AND is a logical operator. So it's a bit apples and oranges, since the comparison operator must be evaluated first to see if the condition is true, then the logical operator is used to evaluate the conditions.