views:

17

answers:

1

I have the below query, everytime i change it i need to change the stockclientid. I would like it where i only have one where statement to apply to all the sub queries.

Is there also a way to apply the same code to return multiple rows? I would like to have the results display for all stockclientIDs rather than just 1.

Select 

(Select distinct SName FROM classifiedadmin.readOnly_CoreData) as SupplierName,

(SELECT COUNT(*) FROM classifiedadmin.readOnly_CoreData where Successful= 1 and StockClientID=3) as TotalLive,

(Select count(*) FROM classifiedadmin.readOnly_CoreData where length(DetailDesc) > 200 and StockClientID= 3) as DescriptionOver200,

(select count(*) from classifiedadmin.readOnly_CoreData where busruleViolated=1 and StockClientID = 3) as BusinessRuleViolated,

(Select count(*) FROM classifiedadmin.readOnly_CoreData where StockClientID = 3
and Successful=0
and busruleviolated=0
and Edition not like '%auto%'
and Edition not like '%shift%'
and Edition not like '%tronic%'
and Edition not like '%van%'
and Edition not like '%DSG%') as UnadvertisedManual;
A: 
SELECT  MIN(sname),
        SUM(Successful= 1),
        SUM(length(DetailDesc) > 200),
        SUM(busruleViolated=1),
        SUM(
        Successful=0
        and busruleviolated=0
        and Edition not like '%auto%'
        and Edition not like '%shift%'
        and Edition not like '%tronic%'
        and Edition not like '%van%'
        and Edition not like '%DSG%'
        )
FROM    classifiedadmin.readOnly_CoreData
WHERE   StockClientID = 3

Note that your current query with SELECT DISINCT sname will fail if there is more than one sname within given stockclientid.

Quassnoi
Thank you so much! Perfect!!!!
David Kyle