thendrickson
Programmer
I receive a syntax error that I cannot quite seem able to find in the following code.
Can some one help me out? I am afraid I have minimal understanding of Informix. I want to call this procedure from SQL Server. I am using Linked servers and need to only select summarized data for a single site by employee
Should be about 239 records maximum
Note: comment lines are not present in the actual procedure yet. I removed them for testing just in case they were the problem
CREATE PROCEDURE ifx_getusebysite(psitecode varchar(50));
Select
-- year to date value by employee for site
(Select SUM(cost * quantity) as sy,employee
from trans where YEAR(transdate) = YEAR(CURRENT)
and site_code = psitecode
GROUP BY employee) as yeartodate,
--month to date value by employee for site
(Select SUM(cost * quantity) as md,employee from trans
where MONTH(transdate) = MONTH(CURRENT) and
YEAR(transdate) = YEAR(CURRENT) and site_code = psitecode
GROUP BY employee) as monthtodate,
--Previous months value (value by employee for site
--Account for DEC/JAN
(Select SUM(cost * quantity) as lm,employee from trans
where MONTH(transdate) = (MONTH(CURRENT) -1) and
(YEAR(transdate) = YEAR(CURRENT) or YEAR(transdate) =
(YEAR(CURRENT) -1)) and site_code = psitecode
GROUP BY employee) as lastmonth,
--daily value by employee for site
(Select SUM(cost * quantity) as ud,employee from trans
where DAY(transdate) = DAY(CURRENT) and
YEAR(transdate) = YEAR(CURRENT) and site_code = psitecode
GROUP BY employee) as usagedaily,
--weekly value by employee for site
--account for month change during the week
(Select SUM(cost * quantity) as uw,employee from trans
where DAY(transdate) <= DAY(CURRENT) and
WEEKDAY(transdate)<= WEEKDAY(CURRENT) and
(YEAR(transdate) = YEAR(CURRENT) or YEAR(transdate) =
(YEAR(CURRENT) -1) and site_code = psitecode
GROUP BY employee) as usageweekly,employee
from trans where site_code = psitecode
END PROCEDURE;
Can some one help me out? I am afraid I have minimal understanding of Informix. I want to call this procedure from SQL Server. I am using Linked servers and need to only select summarized data for a single site by employee
Should be about 239 records maximum
Note: comment lines are not present in the actual procedure yet. I removed them for testing just in case they were the problem
CREATE PROCEDURE ifx_getusebysite(psitecode varchar(50));
Select
-- year to date value by employee for site
(Select SUM(cost * quantity) as sy,employee
from trans where YEAR(transdate) = YEAR(CURRENT)
and site_code = psitecode
GROUP BY employee) as yeartodate,
--month to date value by employee for site
(Select SUM(cost * quantity) as md,employee from trans
where MONTH(transdate) = MONTH(CURRENT) and
YEAR(transdate) = YEAR(CURRENT) and site_code = psitecode
GROUP BY employee) as monthtodate,
--Previous months value (value by employee for site
--Account for DEC/JAN
(Select SUM(cost * quantity) as lm,employee from trans
where MONTH(transdate) = (MONTH(CURRENT) -1) and
(YEAR(transdate) = YEAR(CURRENT) or YEAR(transdate) =
(YEAR(CURRENT) -1)) and site_code = psitecode
GROUP BY employee) as lastmonth,
--daily value by employee for site
(Select SUM(cost * quantity) as ud,employee from trans
where DAY(transdate) = DAY(CURRENT) and
YEAR(transdate) = YEAR(CURRENT) and site_code = psitecode
GROUP BY employee) as usagedaily,
--weekly value by employee for site
--account for month change during the week
(Select SUM(cost * quantity) as uw,employee from trans
where DAY(transdate) <= DAY(CURRENT) and
WEEKDAY(transdate)<= WEEKDAY(CURRENT) and
(YEAR(transdate) = YEAR(CURRENT) or YEAR(transdate) =
(YEAR(CURRENT) -1) and site_code = psitecode
GROUP BY employee) as usageweekly,employee
from trans where site_code = psitecode
END PROCEDURE;