Pad numbers with leading and ending zeros

0

In a recent project, I got a list of integers something similar to following.

1
12
123
1234
12345
….
123456789

and, I was asked to add zeros to the left or right of the list and make it as below.

List 1:
0000000001
0000000012
0000000123
…..
0123456789

List 2:
1000000000
1200000000
1230000000
….
1234567890

C# – PadLeft / PadRight

In C#, you can use PadLeft and PadRight functions to do this.
https://msdn.microsoft.com/en-us/library/system.string.padleft(v=vs.110).aspx

String.PadLeft Method (Int32, Char)
String.PadRight Method (Int32, Char)

int[] numbers = { 1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789 };

Console.WriteLine("List 1");
foreach (var i in numbers)
{
Console.WriteLine(i.ToString().PadLeft(10, '0'));
}

Console.WriteLine();
Console.WriteLine("List 2");
foreach (var i in numbers)
{
Console.WriteLine(i.ToString().PadRight(10, '0'));
}

 

PadLeft and PadRight

PadLeft and PadRight

SQL

Here comes the interesting part, I had to do this using SQL. In SQL there are no inbuilt PadLeft or PadRight functions.  So, I have used the LEFT and RIGHT SQL functions with a small hack.

CREATE TABLE [dbo].[NumberPadding](
[Number] [int] NOT NULL
) ON [PRIMARY]
GO;

INSERT INTO dbo.NumberPadding
VALUES (1), (12), (123), (1234), (12345), (123456), (1234567), (12345678), (123456789)
GO;

SELECT LEFT (CAST([Number] AS VARCHAR) + '0000000000', 10) FROM dbo.NumberPadding;

SELECT RIGHT ('0000000000' + CAST([Number] AS VARCHAR) , 10) FROM dbo.NumberPadding;
SQL - LEFT, RIGHT FUNCTIONS

SQL – LEFT, RIGHT FUNCTIONS

 

 

Windows 10: GodMode

0

GodeMode is a hidden folder trick that allows users to access all of the operating system’s control panels from within a single folder.

To enable “GodMode” feature for Windows 10, you just need to create a new folder and then name the folder as following:
GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}

GodMode: Folder

GodMode: Folder

By default, when you create the GodeMode folder, folder icon change to control panel icon.

Double click the folder and enjoy the features.. 🙂

Windows 10: GodMode

Windows 10: GodMode

Some SQL Tips

0

1.  I am back after a very long break. So, I somehow forgot SQL Server ‘SA’ Password, and this is how I recovered that.

  • Stop SQL SERVER
  • Change the startup parameters by adding add -m;
  • Start SQL Server
  • Open command prompt and type SQLCMD

Method 1:  Create new user and add to systemadmin role

CREATE LOGIN recovery1 WITH PASSWORD = 'abc123%';
sp_addsrvrolemember 'recovery1', 'sysadmin';
GO;

Now login using created user and change the ‘Sa’ password

Method 2: Change Password

EXEC sp_password NULL, abc123!@#$', 'sa';
GO;

Method 3: Give system admin roles to the windows user

EXEC sp_addsrvrolemember 'Softcat\tharaka_r', 'sysadmin';
GO;

2.  I could not remember who wrote this query, but I am sure it was not me. :p  So, I just simplified that.

DECLARE @RunDate AS DATETIME = getdate()
SELECT CONCAT (DATEPART(yyyy,DATEADD(dd,30,@RunDate)),'-', DATEPART(mm,DATEADD(dd,30,@RunDate)),'-', DATEPART(dd,DATEADD(dd,30,@RunDate))) AS DateNow , 30 AS Value;

Simplified version:

DECLARE @RunDate AS DATETIME = getdate();
SELECT CONVERT(VARCHAR(10),DATEADD (dd,30, @RunDate),120) AS DateNow , 30 AS Value;