Handy C#, VB.Net & SQL Code Snippets

Date time – how to initialize a date [code language=”csharp”] DateTime value = new DateTime(2017, 1, 18); [/code] Concatenate string list into comma separated string [code language=”csharp”] List<string> message = new List<string>(); message.Add("Record exists"); message.Add("Invalid data format"); message.Add("Duplicated record"); string output = String.Join(", ", message.Where( m=> (m.Length != 0))); Console.WriteLine(output); [/code] Initialize a string list … More Handy C#, VB.Net & SQL Code Snippets

SQL-Transact Backup all Databases In a MS SQL Server

The Problem My client wants to backup all the databases in their MS SQL Server Server – 1,000 large databases – to a shared network drive. I want to run a script, get coffee and come back to check when the backup is completed. Solution Created a script to backup all the databases on the … More SQL-Transact Backup all Databases In a MS SQL Server

Transact-SQL Server – Transposing a table

The Problem A client sent me an excel sheet with financial information classified in columns where each column header was a date and the values associated with that date were listed below I needed to insert the information to a normalized table with the following columns: Client Account EntryDate Value The Solution Step 1 Loaded … More Transact-SQL Server – Transposing a table

Transfer database permissions on all objects from one SQL server to another – MS SQL Server 2008 – 2014

The Problem I needed to migrate all databases from a MS SQL server 2008 R2 to MS SQL Server 2014; while I can create and restore my databases, permission in objects live on the system databases, therefore I needed to transfer all my login and data objects from one server to another. This cannot be … More Transfer database permissions on all objects from one SQL server to another – MS SQL Server 2008 – 2014