Posts Tagged count

Count occurances of a character in a string

Posted by Ozer Senturk on Tuesday, 9 March, 2010
/// <summary>
/// Counts the number of occurrances of character chr in string str
/// </summary>
/// <param name="str">The string to count character chr in</param>
/// <param name="chr">The character to count in str</param>
/// <returns>The number of occurrances of character chr in string str</returns>
public static int countOccurances(String str, Char chr)
{
    int count = 0;

    for (int i = 0; i < str.Length; i++)
        if (str[i] == chr)
            count++;

    return count;
}

Determining whether a table contains more than 10000000 records or not in SQL Server

Posted by Ozer Senturk on Tuesday, 9 March, 2010
SELECT
 CASE WHEN
  (
   (
    SELECT
     c0
    FROM
     (SELECT TOP 10000000 1 AS c0, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) AS RowNum FROM [policies] AS q0t1) AS x
    WHERE
     x.RowNum BETWEEN 10000000 AND 10000001
   ) IS NOT NULL
  )
 THEN
  1
 ELSE
  0
 END

Listing tables together with their counts in SQL Server

Posted by Ozer Senturk on Tuesday, 9 March, 2010
SELECT
    [TableName] = so.name,
    [RowCount] = MAX(si.rows)
FROM
    sysobjects so,
    sysindexes si
WHERE
    so.xtype = 'U' AND
    si.id = OBJECT_ID(so.name)
GROUP BY
    so.name
ORDER BY
    2 DESC