Tuesday, April 1, 2014

Removing double/ multiple comma from a string in c#

Use namespace:
using System.Text.RegularExpressions;

then do the following code:

string inputString = "'\"1\":\"C\",\"2\":\"A\",\"3\":\"C\",,\"5\":\"C\",\"6\":\"B\",,\"8\":\"C\",,\"10\":\"C\",'";
string outputString = Regex.Replace(inputString, ",{2,}", ",").Trim(',');

Thursday, March 6, 2014

Count Stored Procedures, System Tables, User Defined Tables in any database

USE DATABASENAME
SELECT 
    CASE TYPE 
        WHEN 'U' 
            THEN 'User Defined Tables' 
        WHEN 'S'
            THEN 'System Tables'
        WHEN 'IT'
            THEN 'Internal Tables'
        WHEN 'P'
            THEN 'Stored Procedures'
        WHEN 'PC'
            THEN 'CLR Stored Procedures'
        WHEN 'X'
            THEN 'Extended Stored Procedures'
    END, 
    COUNT(*)     
FROM SYS.OBJECTS
WHERE TYPE IN ('U', 'P', 'PC', 'S', 'IT', 'X')
GROUP BY TYPE