June 21, 2013 at 10:00 am
I am having trouble where it starts with:
AND jomast.fcompany LIKE 'AT&T*', 'Centerpoint*', 'Cingular*', 'Dynis*', 'Global*', 'Sabre*', 'US*', 'Verizon*'
and down.
It does not Like the (Like) statement. I have tried everything.
The bottom half is to go into the database and find all job boms that match AT&T, Centerpoint, etc and if there is a bom, it is to
look at the fparent name and if it ends with '%-10', AVG the fquantity used and place in a new colunm named 'Casting-10' and so on down the line.
SELECT
jomast.fpartno AS 'Bom Part No',
jomast.fdescript AS 'Bom Desc',
jomast.fmeasure AS 'U/M',
inmast.fstdcost AS 'Unit Cost',
inmast.flocate1 AS 'Bin Loc',
inmast.fytdiss AS 'YTD Issued'
FROM m2mdata01.dbo.inboms inboms, m2mdata01.dbo.inmast inmast, m2mdata01.dbo.jomast jomast
WHERE
inboms.identity_column = jomast.identity_column AND inmast.identity_column = inboms.identity_column AND inmast.identity_column = jomast.identity_column
AND jomast.fcompany LIKE 'AT&T*', 'Centerpoint*', 'Cingular*', 'Dynis*', 'Global*', 'Sabre*', 'US*', 'Verizon*'
AND inboms.fparent LIKE '%-10' (AVG(jomast.fquantity)) AS 'Casting-10'
AND inboms.fparent LIKE '%-20' (AVG(jomast.fquantity)) AS 'Carpentry-20'
AND inboms.fparent LIKE '%-30' (AVG(jomast.fquantity)) AS 'Conduit-30'
AND inboms.fparent LIKE '%-40' (AVG(jomast.fquantity)) AS 'Electrical-40'
AND inboms.fparent LIKE '%-50' (AVG(jomast.fquantity)) AS 'Mechanical-50'
AND inboms.fparent LIKE '%-51' (AVG(jomast.fquantity)) AS 'Doors-51'
AND inboms.fparent LIKE '%-75' (AVG(jomast.fquantity)) AS 'Generators-75'
GROUP BY Bom Part No
June 21, 2013 at 10:09 am
You will have to remove all where clauses having aggregate functions like AVG and put them into HAVING clause.
June 21, 2013 at 10:11 am
dudyone (6/21/2013)
I am having trouble where it starts with:AND jomast.fcompany LIKE 'AT&T*', 'Centerpoint*', 'Cingular*', 'Dynis*', 'Global*', 'Sabre*', 'US*', 'Verizon*'
and down.
It does not Like the (Like) statement. I have tried everything.
The bottom half is to go into the database and find all job boms that match AT&T, Centerpoint, etc and if there is a bom, it is to
look at the fparent name and if it ends with '%-10', AVG the fquantity used and place in a new colunm named 'Casting-10' and so on down the line.
SELECT
jomast.fpartno AS 'Bom Part No',
jomast.fdescript AS 'Bom Desc',
jomast.fmeasure AS 'U/M',
inmast.fstdcost AS 'Unit Cost',
inmast.flocate1 AS 'Bin Loc',
inmast.fytdiss AS 'YTD Issued'
FROM m2mdata01.dbo.inboms inboms, m2mdata01.dbo.inmast inmast, m2mdata01.dbo.jomast jomast
WHERE
inboms.identity_column = jomast.identity_column AND inmast.identity_column = inboms.identity_column AND inmast.identity_column = jomast.identity_column
AND jomast.fcompany LIKE 'AT&T*', 'Centerpoint*', 'Cingular*', 'Dynis*', 'Global*', 'Sabre*', 'US*', 'Verizon*'
AND inboms.fparent LIKE '%-10' (AVG(jomast.fquantity)) AS 'Casting-10'
AND inboms.fparent LIKE '%-20' (AVG(jomast.fquantity)) AS 'Carpentry-20'
AND inboms.fparent LIKE '%-30' (AVG(jomast.fquantity)) AS 'Conduit-30'
AND inboms.fparent LIKE '%-40' (AVG(jomast.fquantity)) AS 'Electrical-40'
AND inboms.fparent LIKE '%-50' (AVG(jomast.fquantity)) AS 'Mechanical-50'
AND inboms.fparent LIKE '%-51' (AVG(jomast.fquantity)) AS 'Doors-51'
AND inboms.fparent LIKE '%-75' (AVG(jomast.fquantity)) AS 'Generators-75'
GROUP BY Bom Part No
Your where predicates are incorrect. You can't pass a list of comma delimited values. The line for fcompany will need to be split into multiples.
(
jomast.fcompany LIKE 'AT&T*'
OR jomast.fcompany LIKE 'Centerpoint*'
OR jomast.fcompany LIKE 'Cingular*'
...
)
Then you have the parent lines. I have no idea what you are trying to do there but it won't work.
Also, you are using the old ANSI-89 join syntax by having the tables listed in a row and the join logic in the where clause. This causes lots of confusion. You should instead consider the ANSI-92 join syntax.
Something like this I think:
FROM m2mdata01.dbo.inboms inboms
inner join m2mdata01.dbo.jomast jomast on inboms.identity_column = jomast.identity_column
inner join m2mdata01.dbo.inmast inmast on inmast.identity_column = inboms.identity_column AND inmast.identity_column = jomast.identity_column
Where ...
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
June 21, 2013 at 10:48 am
Yeah, how did I overlook that? Thanks Sean.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply