Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Different syntax question

Status
Not open for further replies.

thendrickson

Programmer
Apr 14, 2004
226
0
0
US
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;
 
I hope you read this before you look at the above too closely!!!!!!!

THere is a really stupid bug in the code.

Please ignore this posting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top