This is my stored procedure:
SELECT artItems.userID, itemID, surname, lastname, gender
FROM artItems INNER JOIN artUser ON artItems.userID = artUser.userID
WHERE (@surname IS NULL OR surname LIKE '%' + @surname + '%')
AND (@lastname IS NULL OR lastname LIKE '%' + @lastname + '%')
ORDER BY lastname
SELECT @numTot = COUNT(gender) FROM artUser WHERE "Same where as above"
I want the @numMale to return the number of female users from the above set by counting in the gender column. I don't wanna have to write the same WHERE clause again, but reuse the previous.
Thanks in advance!
View Complete Post