21 mayo 2018

C# - Generics and Delegates


C# - Generics and Delegates
Método para generar archivo de texto con Generics y Delegates

public class Bo
{
    public static void GenBo()
    {
        #region List Data
        List<Informations> bines = new List<Informations>
        {
        new Informations(1,"604237"),
        new Informations(2,"604238"),
        new Informations(3,"604239"),
        new Informations(4,"604240")
        };
        #endregion
        
        #region Create Directory
        DirectoryInfo directoryInfo = new DirectoryInfo("C:/PR/");
        if (!directoryInfo.Exists) directoryInfo.Create();
        #endregion
        
        #region Write File
        bines.ForEach(delegate (Informations t)
        {
            string filename = directoryInfo + t.Id.ToString() t.Name + ".txt";
            using (FileStream fileStream = new FileStream(filename, 
            FileMode.Create, FileAccess.Write, FileShare.None))
            {
                using (StreamWriter p = new StreamWriter(fileStream))
                {
                    p.WriteLine(t.Id.ToString() + t.Name);
                }
            }
        });
        #endregion
    }
}

public class Informations
{
    public int Id { get; set; }
    public string Name { get; set; }

    public Informations(int Id, string Name)
    {
        this.Id = Id;
        this.Name = Name;
    }
}

24 abril 2018

MS SQL Server - Conteo total de registros por DB

MS SQL Server - Conteo total de registros por DB

Script SQL para realizar el conteo total de registros por table de una base de datos de MS SQL Server.

SELECT
 X.[name],
 REPLACE(CONVERT(varchar, CONVERT(money, X.[rows]), 1), '.00', '') AS [rows],
 REPLACE(CONVERT(varchar, CONVERT(money, X.[reserved]), 1), '.00', '') AS [reserved],
 REPLACE(CONVERT(varchar, CONVERT(money, X.[data]), 1), '.00', '') AS [data],
 REPLACE(CONVERT(varchar, CONVERT(money, X.[index_size]), 1), '.00', '') AS [index_size],
 REPLACE(CONVERT(varchar, CONVERT(money, X.[unused]), 1), '.00', '') AS [unused]
FROM
 (
  SELECT
  CAST(object_name(id) AS varchar(50)) AS [name],
  SUM(CASE WHEN indid < 2 THEN CONVERT(bigint, [rows]) END) AS [rows],
  SUM(CONVERT(bigint, reserved)) * 8 AS reserved,
  SUM(CONVERT(bigint, dpages)) * 8 AS data,
  SUM(CONVERT(bigint, used) - CONVERT(bigint, dpages)) * 8 AS index_size,
  SUM(CONVERT(bigint, reserved) - CONVERT(bigint, used)) * 8 AS unused
  FROM sysindexes WITH (NOLOCK)
  WHERE sysindexes.indid IN (0, 1, 255)
  AND sysindexes.id > 100
  AND object_name(sysindexes.id) <> 'dtproperties'
  GROUP BY sysindexes.id WITH ROLLUP
  ) AS X
WHERE X.[name] is not null
ORDER BY X.[rows] DESC