Skip to content

Instantly share code, notes, and snippets.

@umair-me
umair-me / ReplaceStringSQL.sql
Created October 1, 2013 15:17
Replace string in SQL database via sql query
UPDATE TableName
SET DBTextField = REPLACE(CAST(DBTextField AS varchar(MAX)), 'SearchText', 'ReplaceText')
FROM TableName
WHERE CHARINDEX('SearchText', CAST(DBTextField as varchar(MAX))) > 0
Example:
UPDATE [database].[dbo].[table]
SET [column_name] = REPLACE(CAST([column_name] AS varchar(MAX)), 'OLD_WORD', 'NEW_WORD')
FROM [database].[dbo].[table]
@umair-me
umair-me / gist:6933583
Created October 11, 2013 12:05
List of datetime strings
From: http://www.csharp-examples.net/string-format-datetime/
String Format for DateTime [C#]
This example shows how to format DateTime using String.Format method. All formatting can be done also using DateTime.ToString method.
Custom DateTime Formatting
There are following custom format specifiers y (year), M (month), d (day), h (hour 12), H (hour 24), m (minute), s (second), f (second fraction), F (second fraction, trailing zeroes are trimmed), t (P.M or A.M) and z (time zone).
AjaxJsonPostCall = function (fullUrl, dataObj, callbackFunction) {
$.ajax({
type: 'post',
url: fullUrl,
data: JSON.stringify(dataObj),
dataType: 'json',
cache: false,
success: function (data) { callbackFunction(GetJson(data)); },
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log("error :" + XMLHttpRequest.responseText);
@umair-me
umair-me / new_gist_file
Created October 23, 2013 22:16
Migrate or Clone tfvc tfs to git using git-tfs
http://gitstack.com/how-to-migrate-from-tfs-to-git/
http://stackoverflow.com/questions/19548659/migrate-from-tfs-to-git-on-visualstudio-com/19550144
git-tfs clone --username=mumair85 --password=xxxx https://mumair85.visualstudio.com/DefaultCollection $/uGen
After that clone the new repository or Push an existing repository
From Visual Studio
You can Push a repository after connecting with Team Explorer and adding the Git repo to your list of Local Git Repositories.
@umair-me
umair-me / new_gist_file
Created October 24, 2013 14:55
time timespan in words - return relative time between two given dates
public string TimespanInWords(DateTime oDtTo, DateTime oDtFrom)
{
TimeSpan oTs = oDtTo >= oDtFrom ? oDtTo - oDtFrom : oDtFrom - oDtTo;
if (oTs.TotalSeconds < 30)
return "less than a minute";
if (oTs.TotalSeconds < 90)
return "1 minute";
if (oTs.TotalSeconds < 44 * 60 + 30)
return (int)oTs.TotalMinutes + " minutes";
if (oTs < new TimeSpan(0, 89, 30))
@umair-me
umair-me / new_gist_file
Created October 24, 2013 15:56
convert timespan to readable string format
public static string ToReadableString(this TimeSpan span)
{
string formatted = string.Format("{0}{1}{2}{3}",
span.Duration().Days > 0 ? string.Format("{0:0} day{1}, ", span.Days, span.Days == 1 ? String.Empty : "s") : string.Empty,
span.Duration().Hours > 0 ? string.Format("{0:0} hour{1}, ", span.Hours, span.Hours == 1 ? String.Empty : "s") : string.Empty,
span.Duration().Minutes > 0 ? string.Format("{0:0} minute{1}, ", span.Minutes, span.Minutes == 1 ? String.Empty : "s") : string.Empty,
span.Duration().Seconds > 0 ? string.Format("{0:0} second{1}", span.Seconds, span.Seconds == 1 ? String.Empty : "s") : string.Empty);
if (formatted.EndsWith(", ")) formatted = formatted.Substring(0, formatted.Length - 2);
@umair-me
umair-me / next_identity.sql
Last active December 26, 2015 20:59
Get next identity key id
USE DATABASENAME
GO
SELECT IDENT_CURRENT('TABLENAME') + IDENT_INCR('TABLENAME')
/*Simple table grid style:*/
table.gridtable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
@umair-me
umair-me / close_all_connections.sql
Last active January 19, 2016 16:07
Close all connections SQL server database
USE master
GO
ALTER DATABASE YourDatabaseName
SET OFFLINE WITH ROLLBACK IMMEDIATE
GO
@umair-me
umair-me / select_by_datetime.sql
Last active November 3, 2015 11:22
Get records between two 2 dates
SELECT *
FROM TABLE
where datetime >= Convert(datetime, '2014-01-17 00:00:01', 120)
AND datetime <= Convert(datetime, '2014-01-17 23:59:01', 120)