I know there must be a way to achieve this, so, here we are again :DNeed to change the select according to what the param is...SELECT a.ImportAlertID, a.ClientID, --IF @type = 1 then use this select (SELECT COUNT(*) FROM invoicenotadvanced WHERE NAStatus = 0 AND a.ImportAlertID = ImportAlertID) AS numNA0, --IF @type = 2 then use this select (SELECT COUNT(*) FROM customer WHERE NAStatus = 'Not Sent' AND a.ImportAlertID = ImportAlertID) AS numNA0, a.CompleteStatus, a.CompletedBy FROM ImportAlert aINNER JOIN ImportType b ON a.ImportTypeID = b.ImportTypeIDINNER JOIN Client c ON a.ClientID = c.pk_idINNER JOIN (SELECT ImportAlertID, COUNT(*) AS numCustomers FROM customer GROUP BY ImportAlertID) cust ON a.ImportAlertID = cust.ImportAlertIDINNER JOIN (SELECT ImportAlertID, COUNT(*) AS numInvoices, SUM(invorigamt) AS sumInvoices FROM dbo.invoicenotadvanced GROUP BY ImportAlertID) inv ON a.ImportAlertID = inv.ImportAlertID
How can this be done?A case statement won't work here.Thanks,Zath