HI,
I've to write stored procedures for count the records based on some conditions.For example,I have table with name,address,number,new totally 4 fields.Here "new" field is filled by True or False.Now i've to write stored procedures to count the records which have "True" in "new" field and which have "False" in "new" field.Can anyone help me to do this?
StoredProcedures to count records
5 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Kiresh Gangariya52 reputationPosted Jun 16, 2013, 9:46 PM EDT
SELECT
Count(Id) AS TotalCount FROM TableName where new = 1 UNION SELECT Count(Id) AS TotalCount FROM TableName where new = 0
Sunny SharmaRank #223 · 11.1K reputationPosted Jun 16, 2013, 9:42 PM EDT
use the pattern below:
-------------------------------
CREATE PROCEDURE CountRecords
AS
BEGIN
SELECT COUNT(name) FROM MyTable where new=0;
END
---------------------------
Hope it helps :)
Kavi sujaRank #6,237 · 272 reputationPosted Jun 16, 2013, 10:02 PM EDT
Kavi sujaRank #6,237 · 272 reputationPosted Jun 16, 2013, 10:02 PM EDT
Kiresh Gangariya52 reputationPosted Jun 16, 2013, 10:11 PM EDT