Posts

Merge Two Git Repositories

Here is the step to merge two git repositories: Let's say you have a project name X and another project name Y with same codebase but some different commit ahead/ behind of project X. So you want to merge all the code from project-Y to project-X. Let's assume you are already in the project-X. git remote add project-Y path/to/project-Y  git fetch project-Y --tags git merge --allow-unrelated-histories project-Y/master  (note: Mention the branch name you want to merged with) git remote remove project-Y Thank you

SQL Update From One Table To Another Based On a ID Match

Here is the command for SQL update column with value from another table UPDATE t1 SET      t1.Column = t2.Column, FROM      TableOne t1      INNER JOIN TableTwo t2      ON t1.Column = t2.Column; Go

How to remove all the files and folders from github repository?

To Delete all elements in the repository, use the following command $ git rm -r * then: $ git commit -m 'Delete all the stuff from repository'

Custom Function string_split for SQL Server 2008R2 (T-SQL split string)

For Those who have problem using  string_split function in SQL Server 2008R2 CREATE FUNCTION dbo.string_split (     @stringToSplit VARCHAR(MAX),     @separator VARCHAR(MAX) ) RETURNS   @returnList TABLE ([value] [nvarchar] (500)) AS BEGIN  DECLARE @name NVARCHAR(255)  DECLARE @pos INT  WHILE CHARINDEX(@separator, @stringToSplit) > 0  BEGIN   SELECT @pos  = CHARINDEX(@separator, @stringToSplit)    SELECT @name = SUBSTRING(@stringToSplit, 1, @pos-1)   INSERT INTO @returnList   SELECT @name   SELECT @stringToSplit = SUBSTRING(@stringToSplit, @pos+1, LEN(@stringToSplit)-@pos)  END  INSERT INTO @returnList  SELECT @stringToSplit  RETURN END

Find the number of columns in a table

Though its a rare situation when we need to know the number of columns in a table. You can get the number of columns information for a particular table by running the following query on SQL Server SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_catalog = ' Your_Database_Name '  AND table_name = ' Your_Table_Name ' Good luck!

How To Generate Random Dates Between Two Date Range in SQL Server

Those who wants to generate random dates between two date ranges in SQL Server can use the following query: DECLARE @FromDate DATETIME = DATEADD(DAY, -2, '2011-01-01') DECLARE @ToDate   DATETIME = DATEADD(DAY, -1, '2017-01-01') DECLARE @Seconds INT = DATEDIFF(SECOND, @FromDate, @ToDate) DECLARE @Random INT = ROUND(((@Seconds-1) * RAND()), 0) DECLARE @Milliseconds INT = ROUND((999 * RAND()), 0) SELECT DATEADD(MILLISECOND, @Milliseconds, DATEADD(SECOND, @Random, @FromDate)) Hope it works for you!

Find all tables and views containing column with specified name

Many of us some times wants to know that where a specific column is located as reference to other tables or views. If this is the case for you, then you can execute the following query:  Just replace the YourColumnName with your desired column name.  SELECT      COLUMN_NAME AS 'ColumnName' , TABLE_NAME AS  'TableName' FROM          INFORMATION_SCHEMA.COLUMNS WHERE       COLUMN_NAME LIKE '% YourColumnName %' ORDER BY  TableName , ColumnName; Please note that, if you follow the convention to place every where with same column name, then it will brings good output result for you. Thanks