When using UNION or UNION ALL in a GROUP BY query using alasql (https://github.com/agershun/alasql), only results from table1 are retrieved.
Running separate queries outputs correct results instead.
See this jfiddle http://jsfiddle.net/L8471bnk/116/
var data= [
{"label":"transport - car","value":800},
{"label":"airplane","value":234},
{"label":"train","value":500},
{"label":"glider","value":123},
{"label":"transport - motorbike","value":50},
{"label":"transport - bike","value":150}
];
var query1 = alasql('' +
'SELECT \'transport\' AS label, SUM(CAST([value] AS INT)) AS [value] ' +
'FROM ? ' +
'WHERE label LIKE \'%transport%\' ' +
'GROUP BY \'transport\' ' +
'',
[data]);
var query2 = alasql('' +
'SELECT label, SUM(CAST([value] AS INT)) AS [value] ' +
'FROM ? ' +
'WHERE label NOT LIKE \'%transport%\' ' +
'GROUP BY label' +
'',
[data]);
var queryUnion = alasql('' +
'SELECT \'transport\' AS label, SUM(CAST([value] AS INT)) AS [value] ' +
'FROM ? ' +
'WHERE label LIKE \'%transport%\' ' +
'GROUP BY \'transport\' ' +
'UNION ALL ' + //or UNION, same result!
'SELECT label, SUM(CAST([value] AS INT)) AS [value] ' +
'FROM ? ' +
'WHERE label NOT LIKE \'%transport%\' ' +
'GROUP BY label' +
'',
[data, data]);
$("#res").html("<br/>UNION IS WRONG (length is correct, but query2 results are missing!!!)!<br/>" + JSON.stringify(queryUnion) + " LENGTH: " + queryUnion.length);
$("#info").html("<br/>Query1 is correct:<br/>"
+ JSON.stringify(query1)
+ " LENGTH: " + query1.length
+ "<br/><br/>Query2 is correct<br/>" + JSON.stringify(query2)
+ " LENGTH: " + query2.length);
Just found out: it seems like it's a bug?
See https://github.com/agershun/alasql/issues/485
:(((
Related
In this case i want to null check by using column IS NULL..here column specify uniquename.
Uniquename is a integer column.
filterExpression = objColumnSettings.UniqueName + ' <> ' + objColumnSettings.FilterValue + ' AND ';
Here i have done like this.
This works but i want to use column IS NULL rather than ISNULL(column, value)
filterExpression = " ISNULL( " + objColumnSettings.UniqueName + " , 0 ) " + ' <> ' + objColumnSettings.FilterValue + ' AND ';
Please suggest
Thanks in advance;
should be
filterExpression = objColumnSettings.UniqueName + " IS NUL OR " + objColumnSettings.UniqueName + ' <> ' + objColumnSettings.FilterValue + ' AND ';
I working on one application, and I started learning ASP.NET so I am begginer and I am trying to add one field in view.
So, I have Firstname,Address, ZIP, State etc and I want for every medical provider add his|her speciality. I create a table and make connection beatween two table.
When I add SPeciality, it doesnt show up in view. I have no idea where I made mistake.
https://i.imgur.com/YBc5dVZ.jpg
https://i.imgur.com/m0haaIW.jpg
https://i.imgur.com/mAvjNLc.jpg
var id = $(this).attr('data-id');
$.getJSON("/NfDocuments/MedicalInput", { id: id },
function (data) {
$('#medInput').empty();
$.each(data, function () {
// $("#medInput").append("'" + this.Id + "'");
//console.log(this.Id);
var medInput = document.getElementById("medInput");
medInput.value = this.Firstname + ' - ' + this.Zip + ' ' + this.Address1 + ',' + this.City + ', ' + this.State + ' - ' + this.Mobile;
});
});
Any suggestion, comment ?
medInput.value = this.Firstname + ' - '
+ this.Zip + ' '
+ this.Address1 + ','
+ this.City + ', '
+ this.State + ' - '
+ this.Mobile;
You need to append this.SpecialityName (or whatever you have it named as when returned to the view) to medInput.Value:
medInput.value = this.Firstname + ' - '
+ this.Zip + ' '
+ this.Address1 + ','
+ this.City + ', '
+ this.State + ' - '
+ this.Mobile + ' - '
+ this.SpecialityName;
I'm assuming the id of each speciality is this.TypeId and that you have already mapped TypeId to some kind of SpecialityName before sending the object back to the view.
var report = AdWordsApp.report(
'SELECT Id, Criteria, CpcBid, FirstPageCpc, FirstPositionCpc, TopOfPageCpc, Criteria ' +
'FROM KEYWORDS_PERFORMANCE_REPORT ' +
'WHERE' +
'Id = 14317961 ' +
'DURING LAST_7_DAYS ');
var rows = report.rows();
while(rows.hasNext()) {
var row = rows.next();
var keywordIdReport = row['Id'];
var keywordNameReport = row['Criteria'];
var cpcBid = row['CpcBid'];
var firstPageCpc = row['FirstPageCpc'];
var firstPositionCpc = row['FirstPositionCpc'];
var topOfPageCpc = row['TopOfPageCpc'];
Logger.log('KeywordIdReport :' + keywordIdReport)
Logger.log('CPCbid :' + cpcBid)
Logger.log('firstPositionCpc : ' + firstPositionCpc)
Logger.log('topOfPageCpc : ' + topOfPageCpc)
Logger.log('firstPageCpc : ' + firstPageCpc)
}
I don't understand why, but the Adwords IDE tell me that the condition WHERE Id = 14317961 in my query is invalid, but I can't explain it is wrong. Assume here that the current Id exists. The purpose of that query is to access the three fields firstPositionCpc, topOfPageCpc and firstPageCpc for the specific keyword id. How could I fix my problem?
Try giving a space after your where clause 'WHERE ' +.
There is no space after the 'WHERE' +
Add a space after it 'WHERE ' +.
missing space after " WHERE "
var report = AdWordsApp.report(
'SELECT Id, Criteria, CpcBid, FirstPageCpc, FirstPositionCpc, TopOfPageCpc, Criteria ' +
'FROM KEYWORDS_PERFORMANCE_REPORT ' +
'WHERE ' + <----- space was missing
'Id = 14317961 ' +
'DURING LAST_7_DAYS ');
In your query, no spaces are available between 'where' and 'ID', please add a space between those.
'WHERE ' +
'Id = 14317961 ' +
You are just missing the space after the WHERE keyword, it should be as shown below:
var report = AdWordsApp.report(
'SELECT Id, Criteria, CpcBid, FirstPageCpc, FirstPositionCpc, TopOfPageCpc, Criteria ' +
'FROM KEYWORDS_PERFORMANCE_REPORT ' +
'WHERE ' +
'Id = 14317961 ' +
'DURING LAST_7_DAYS ');
I am returning an object from a site which apart from other parameters also contains an array of objects.
If I do console.log(req.body.cart) I print this [ { title: 'iphone 6', cost: '650' } ]
which I need only the title. I tried stringify, which is not what I want and parse which returned an 500 error.
router.post('/itemstobuy', function(req, res, next){
if(!req.body.name || !req.body.lastname || !req.body.address
|| !req.body.email || !req.body.cart){
return res.status(400).json({message: 'Please fill out all fields'});
}
var mailOptions={
from: 'anEmail#gmail.com',
to: 'anotherEmail#gmail.com',
subject: 'Subject',
html: '<p>Name: ' + req.body.name + '</p>' +
'<p>LastName: ' + req.body.lastname + '</p>' +
'<p>Address: ' + req.body.address + '</p>' +
'<p>Email: ' + req.body.email + '</p>' +
'<p>Cart: ' + JSON.stringify(req.body.cart) + '</p>'
}
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
return res.status(200);
});
I need to show the items by their title at
'<p>Cart: ' + JSON.stringify(req.body.cart) + '</p>'
The above works but there are lots of ugly data and need just the titles of the items.
As suggested in the comments:
'<p>Cart: ' +
(req.body.cart || []) //Just to make things not crash and burn if we have no cart
//Take the title from each of the items
.map(function(item){ return item.title; })
//Create a comma-separated string from the titles
.join(', ') +
'</p>'
Try this. '<p>Cart: ' + JSON.parse(req.body.cart).title + '</p>'
In case you have multiple items in the cart you can iterate through these otherwise you can access it directly req.body.cart[0].title
var cart = req.body.cart;
var html: '<p>Name: ' + req.body.name + '</p>' +
'<p>LastName: ' + req.body.lastname + '</p>' +
'<p>Address: ' + req.body.address + '</p>' +
'<p>Email: ' + req.body.email + '</p>';
html += '<p>Cart:<ul> '+
for(var i=0;i<cart.length;i++) html +='<li> ' + cart[i].title + '</li>';
html +='</ul></p>';
var cart = [ { title: 'iphone 6', cost: '650' }, { title: 'iphone 5', cost: '550' } ];
document.write( '<p>Cart:<ul> ');
for(var i=0;i<cart.length;i++) document.write('<li> ' + cart[i].title + '</li>');
document.write('</ul></p>');
I have an Array which is like:
var Arr = [
{ forname: 'John', surname: 'Doe', email: 'johndoe#gmail.com', website: 'www.johndoe.com', phone: '0123456789', img: 'img/johndoe.jpg' },
{ forname: 'Jane', surname: 'Doe', email: '', website: 'www.janedoe.com', phone: '0123456789', img: 'img/janedoe.jpg' },
]
what I do is filling a div with id="#caption"
$('#caption').html(e[f].forname + ' ' + e[f].surname + '<br>' + e[f].email + '<br>' + e[f].website + '<br>' + e[f].phone);
e and f are parameter passed through a function and they select each array object. The problem I have now is, when I get the data of both in the caption div it looks like:
because Jane Doe has no E-Mail adress. I don't know who and which fields are having a value or not. What I want to do is, that fields with no value get the double <br> removed.
Thanks!
Try instead of using <br> blocks (denote where the line breaks are) use <div>s (denote where the lines are). Like <p>aragraphs, they use a line each because of the default display: block property, but have fewer default-formatting properties.
You could use some trickery
[
e[f].forname+" "+e[f].surname,
e[f].email,
e[f].website,
e[f].phone
].filter(function(n){ return n != undefined && n != ''; }).join('<br/>');
Any empty values will be skipped and no double will be added
If it is an empty string:
$('#caption').html(e[f].forname + ' ' + e[f].surname + '<br>' + e[f].email + (( e[f].email=="")?"":'<br>') + e[f].website + '<br>' + e[f].phone);
(and if it's null you can check four null)
just check if it's empty and if it's empty -> don't put <br>
Just use the tenary operator.
insted of
+ e[f].email + '<br>' +
try
+ (e[f].email ? e[f].email + '<br>' : '') +
This will insert email + '<br>' only if there is an email.
Do this for all fields.
EDIT
$('#caption').html(
e[f].forname + ' ' + (e[f].surname ? e[f].surname + '<br>' : '') +
(e[f].email ? e[f].email + '<br>' : '') +
(e[f].website ? e[f].website + '<br>' : '')
(e[f].phone ? e[f].phone + '<br>' : ''
);