Wednesday, 26 April 2017

Why does my sql statement work in my editor but not my JS function?

I have sql statement that works perfectly fine running it in my sql editor but when I i put it in my javascript function it tells me invalid column for my client id.

function getFeedposts(data) {
 var limit = data.dollarLimit;
 var client_id = data.salesforce_username;
 var sqlQuery = `select coalesce(advertiser,'') as advertiser, 
coalesce(partner,'') as partner, 
coalesce(advertiser,'') || ' via ' || coalesce(partner,'') as line1,
' - SSP: blah' as line2,
' - Lead Date: ' || date as line3,
'Yesterday''s Activity' as line4,
 ' - Impressions: ' || coalesce(impressions,0) as line5,
 ' - CPM: $' || coalesce(round(ecpm,2),0) as line6,
 ' - Spend: $' || coalesce(round(revenue,2),0) as line7,
 'Yesterday''s Spend Breakout' as line7a,
 coalesce(device_type,'') as line8,
'Running Spend Totals' as line9,
 ' - 3 Day Spend: $' || coalesce(round(three,2),0) as line10,
 ' - 7 Day Spend: $' || coalesce(round(seven,2),0) as line11,
 ' - 30 Day Spend: $' || coalesce(round(thirty,2),0) as line12,
 coalesce(round(thirty,2),0) as line13,
 coalesce(round(seven,2),0) as line14,
 coalesce(round(three,2),0) as line15,
 coalesce(round(three,2),0) as line15,
 client_id as client_id
 from
 (select advertiser, partner, date, impressions, ecpm, revenue,       device_type, client_id
 ,(select sum(m.revenue)
 FROM blahblah as m
 WHERE m.date > rl.date -30
 and advertiser = rl.advertiser
 and partner = rl.partner
GROUP BY partner, advertiser) as thirty
,(select sum(m.revenue)
FROM blahblah as m
WHERE m.date > rl.date -7
and advertiser = rl.advertiser
and partner = rl.partner
GROUP BY partner, advertiser) as seven
,(select sum(revenue)
FROM blahblah as m
WHERE m.date > rl.date -3
and advertiser = rl.advertiser
and partner = rl.partner
GROUP BY partner, advertiser) as three
from blahblah as rl
) as idunno
WHERE 
date = to_date('${data.date}','mm-dd-yyyy')
and revenue > 1 and client_id ='myemail@email.com'
`;
queryRDS(sqlQuery, data);
}

this works but when i do

 function getFeedposts(data) {
 var limit = data.dollarLimit;
 var client_id = data.salesforce_username;
 var sqlQuery = `select coalesce(advertiser,'') as advertiser, 
coalesce(partner,'') as partner, 
coalesce(advertiser,'') || ' via ' || coalesce(partner,'') as line1,
' - SSP: blah' as line2,
' - Lead Date: ' || date as line3,
'Yesterday''s Activity' as line4,
 ' - Impressions: ' || coalesce(impressions,0) as line5,
 ' - CPM: $' || coalesce(round(ecpm,2),0) as line6,
 ' - Spend: $' || coalesce(round(revenue,2),0) as line7,
 'Yesterday''s Spend Breakout' as line7a,
 coalesce(device_type,'') as line8,
'Running Spend Totals' as line9,
 ' - 3 Day Spend: $' || coalesce(round(three,2),0) as line10,
 ' - 7 Day Spend: $' || coalesce(round(seven,2),0) as line11,
 ' - 30 Day Spend: $' || coalesce(round(thirty,2),0) as line12,
 coalesce(round(thirty,2),0) as line13,
 coalesce(round(seven,2),0) as line14,
 coalesce(round(three,2),0) as line15,
 coalesce(round(three,2),0) as line15,
 client_id as client_id
 from
 (select advertiser, partner, date, impressions, ecpm, revenue,       device_type, client_id
 ,(select sum(m.revenue)
 FROM blahblah as m
 WHERE m.date > rl.date -30
 and advertiser = rl.advertiser
 and partner = rl.partner
GROUP BY partner, advertiser) as thirty
,(select sum(m.revenue)
FROM blahblah as m
WHERE m.date > rl.date -7
and advertiser = rl.advertiser
and partner = rl.partner
GROUP BY partner, advertiser) as seven
,(select sum(revenue)
FROM blahblah as m
WHERE m.date > rl.date -3
and advertiser = rl.advertiser
and partner = rl.partner
GROUP BY partner, advertiser) as three
from blahblah as rl
) as idunno
WHERE 
date = to_date('${data.date}','mm-dd-yyyy')
and revenue >
 `;
  sqlQuery += limit + 'and client_id =' + client_id;

  queryRDS(sqlQuery, data);
   }

I would like to know why it tells invalid column for the email address that is the current client_id when doing it like this but when I hard code it it works perfectly fine any help would be greatly appreciated



via Joseph Mckenzie

No comments:

Post a Comment