I need to put 2 different values for 1 variable in the LoadScript of a report.
I am using the syntax with let -
LET Customer_name ='XXXX';
LET Customer_name ='YYYY';
But when I load data, I have data only for one customer but not the second one as well.
I solved the problem -
I created 2 variables -
LET Customer_name ='XXXX';
LET Customer_name2 ='YYYY';
and in the Load Script I called them in the WHERE CLAUSE with OR.
WHERE Customer_name = 'XXXX' OR Customer_name2 = 'YYYY';
Related
I need to change the sku directly in the commerce_product table and want to know if this is possible to do without creating a drush script.
This can be done by changing the same sku in both commerce_product & commerce_product_revision then truncating all of the cache tables.
UPDATE `commerce_product` SET `sku` = 456 WHERE `sku` = 123;
UPDATE `commerce_product_revision` SET `sku` = 456 WHERE `sku` = 123;
I am trying to create a new report with a filter based on another query.
For instance I have a bunch of fields and want to add this type of filter:
if place code = '22' then provider state = 'PA' else no filter.
I have tried writing to separate queries; I've tried some case if, case when scenarios that all fail when testing the code.
case when ([place_code] = '22' then [provider_state] = 'PA' ) end
There is just too many results if I don't put in this filter.
I ultimately need all place_code's and the respective provider_states but when it's place_code 22 I only want to see provider_state's of 'PA'
Another approach is to use master detail
Have 2 queries
Query 1 has the main content
Query 2 has the [provider_state] data and is joined to Query 1
If there is a provider state, then the detail query will show the results, otherwise it will be blank
Try something like
Create the Data Item [State Selected]
Note: the XX value is an impossible scenario on purpose
case
when ([place_code]='')Then('XX')
when ([place_code]='22')Then('PA')
when ([place_code]='21')Then('TN')
..
END
Have a filter with an "OR" condition
([State Selected] <> 'XX' AND [provider_state] = [State Selected])
OR
([State Selected] = 'XX' AND [provider_state] <> [State Selected])
This way if there is a valid filter, it is applied
If there is no filter, then the other part of the OR statement takes place making the filter behave as if disabled
I am trying to pull some logged events from Application Insights into our SQL database. I have no control over the format of the inputs which are json files composed of multiple json arrays within the file. In each record, 5 pieces of information are in a json array at [context].[custom].[dimensions] in the file and using an OUTER APPLY flattens these values. The problem is it returns results not as one row per record but as though you had joined one row with 5 (which is indeed what it has done) and the values of the 5 pieces of data are NULL in 4 cases and the actual value in the other. I only need 2 of the 5 values - PageType and UserId - and given this in my GROUP BY it returns 3 records, one with each value and one with both of them null.
In normal SQL you would simply use a MAX expression to get the real values for each but in Stream Analytics you can't use MAX on strings. You also can't use COALESCE and a number of other methods I tried to resolve this with. Any ideas how the results can be changed from:
EventDateTime Event PageType UserId AppVersion CountA
2017-05-24 Nav Show NULL NULL 2.0.1293 1
2017-05-24 Nav Show NULL SIRTSW 2.0.1293 1
2017-05-24 Nav Show Trade NULL 2.0.1293 1
to
2017-05-24 Nav Show Trade SIRTSW 2.0.1293 1 ?
The code that returns three rows for each is as follows (note that e.event is an array of one item so it does not cause the same issue):
SELECT flatEvent.ArrayValue.name as Event,
e.context.data.eventTime as EventDateTime,
e.context.application.version as AppVersion
,flatCustom.ArrayValue.UserId as UserId
,flatCustom.ArrayValue.PageType as PageType,
SUM(flatEvent.ArrayValue.count) as CountA
INTO
[insights]
FROM [ios] e
CROSS APPLY GetArrayElements(e.[event]) as flatEvent
OUTER APPLY GetArrayElements(e.[context].[custom].[dimensions]) as flatCustom
GROUP BY SlidingWindow(minute, 1),
flatEvent.ArrayValue.name,
e.context.data.eventTime,
e.context.application.version,
flatCustom.ArrayValue.UserId,
flatCustom.ArrayValue.PageType
Thanks in advance,
Rob
According to your scenario, I assumed that you could use JavaScript user-defined functions for Azure Stream Analytics to coalesce the multiple dimensions into a single record. Here are my test for this issue, you could refer to them.
JSON file
{
"context":{
"data":{"eventTime":"2017-05-24"},
"application":{"version":"2.0.1293"},
"custom":{
"dimensions":[
{"PageType":null,"UserId":"SIRTSW"},
{"PageType":"Trade","UserId":null},
{"PageType":null,"UserId":null}
]
}
},
"event":[
{"name":"Nav Show","count":1}
]
}
javascript UDF, UDF.coalesce
function main(items) {
var result=[];
var UserIdStr="",PageTypeStr="";
for(var i=0;i<items.length;i++){
if(items[i].UserId!=null && items[i].UserId!=undefined)
UserIdStr+=items[i].UserId;
if(items[i].PageType!=null && items[i].PageType!=undefined)
PageTypeStr+=items[i].PageType;
}
result.push({UserId:UserIdStr,PageType:PageTypeStr});
return result;
}
Query
--first query
WITH f AS (
SELECT
e.context.data.eventTime as EventDateTime,
e.context.application.version as AppVersion,
e.event as flatEvent,
UDF.coalesce(e.[context].[custom].[dimensions]) as flatDimensions
FROM [ios] e
)
--second query
SELECT flatEvent.ArrayValue.name as Event,
f.EventDateTime,
f.AppVersion,
flatDimension.ArrayValue.UserId,
flatDimension.ArrayValue.PageType,
SUM(flatEvent.ArrayValue.count) as CountA
FROM f
CROSS APPLY GetArrayElements(f.[flatEvent]) as flatEvent
OUTER APPLY GetArrayElements(f.[flatDimensions]) as flatDimension
GROUP BY SlidingWindow(minute, 1),
flatEvent.ArrayValue.name,
f.EventDateTime,
f.AppVersion,
flatDimension.ArrayValue.UserId,
flatDimension.ArrayValue.PageType
TEST RESULT
SQL - How can I return a value from a different table base on a parameter
First time poster, long time reader:
I am using a custom Excel function that allows be to pass parameters and build a SQL string that returns a value. This is working fine. However, I would like to choose among various tables based on the parameters that are passed.
At the moment I have two working functions with SQL statements look like this:
_______FUNCTION ONE________
<SQLText>
SELECT PRODDTA.TABLE1.T1DESC as DESCRIPTION
FROM PRODDTA.TABLE1
WHERE PRODDTA.TABLE1.T1KEY = '&PARM02'</SQLText>
_______FUNCTION TWO________
<SQLText>
SELECT PRODDTA.TABLE2.T2DESC as DESCRIPTION
FROM PRODDTA.TABLE2
WHERE PRODDTA.TABLE2.T2KEY = '&PARM02'</SQLText>
So I am using IF logic in Excel to check the first parameter and decide which function to use.
It would be much better if I could do a single SQL statement that could pick the right table based on the 1st parameter. Logically something like this:
_______FUNCTIONS COMBINED________
IF '&PARM02' = “A” THEN
SELECT PRODDTA.TABLE1.T1DESC as DESCRIPTION
FROM PRODDTA.TABLE1
WHERE PRODDTA.TABLE1.T1KEY = '&PARM02'
ELSE IF '&PARM02' = “B” THEN
SELECT PRODDTA.TABLE2.T2DESC as DESCRIPTION
FROM PRODDTA.TABLE2
WHERE PRODDTA.TABLE2.T2KEY = '&PARM02'
ELSE
DESCRIPTION = “”
Based on another post Querying different table based on a parameter I tried this exact syntax with no success
<SQLText>
IF'&PARM02'= "A"
BEGIN
SELECT PRODDTA.F0101.ABALPH as DESCRIPTION
FROM PRODDTA.F0101
WHERE PRODDTA.F0101.ABAN8 = '&PARM02'
END ELSE
BEGIN
SELECT PRODDTA.F4801.WADL01 as DESCRIPTION
FROM PRODDTA.F4801
WHERE PRODDTA.F4801.WADOCO = '&PARM02'
END</SQLText>
You could try using a JOIN statement.
http://www.sqlfiddle.com/#!9/23461d/1
Here is a fiddle showing two tables.
The following code snip will give you the values from both tables, using the Key as the matching logic.
SELECT Table1.description, Table1.key, Table2.description
from Table1
Join Table2 on Table1.key = Table2.key
Here's one way to do it. If PARM03='Use Table1' then the top half of the union will return records and vice versa. This won't necessarily product good performance though. You should consider why you are storing data in this way. It looks like you are partitioning data across different tables which is a bad idea.
SELECT PRODDTA.TABLE1.T1DESC as DESCRIPTION
FROM PRODDTA.TABLE1
WHERE PRODDTA.TABLE1.T1KEY = '&PARM02'
AND &PARM03='Use Table1'
UNION ALL
SELECT PRODDTA.TABLE2.T2DESC as DESCRIPTION
FROM PRODDTA.TABLE2
WHERE PRODDTA.TABLE2.T2KEY = '&PARM02'</SQLText>
AND &PARM03='Use Table2'
I'm using sql server compact 4 and i have run into a little snag. I have a table named Counter where i store some information 0-2 and it checks the todays date in that table, grabs the CounterValue and put them into one variable each 0,1,2 and present itself as a counter. The next day the new data will have a new date and will present the same values in each variable.
So far so good, if i run the SQL query as follows
SELECT * FROM Counter WHERE Dateis = '21-05-2014'
It present the correct values but when i try the Select from Razor it nothing is executed and it's driving me bonkers.
var DateNow = DateTime.Now.ToString("dd-MM-yyyy");
var CaseCounter = db.Query("SELECT * FROM Counter WHERE Dateis ='DateNow'");
DateNow has the value of 21-05-2014, the same as the sql query i tested have but it does nothing. No data is presented. If i remove the WHERE data will be displayed but then i displays all Dates data and not the current date.
Am i missing something here?
Thanks in advance.
You need to actually patch in the value of the variable, rather than the name of the variable:
var DateNow = DateTime.Now.ToString("dd-MM-yyyy");
var CaseCounter = db.Query("SELECT * FROM Counter WHERE Dateis = '" + DateNow + "'");
Your original code is literally submitting this command to the DB:
SELECT * FROM Counter WHERE Dateis = 'DateNow'
So instead you need to close the string with the double-quote, then a concatenation operator (the + ) and then your variable, before concatenating the closing quote.