This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @sourcebackupfolder varchar(255), @targetbackupfolder varchar(255), @targetdatafolder varchar(255), @targetlogfilder varchar(255) | |
select @sourcebackupfolder = 'c:\moving\', @targetbackupfolder='d:\moving\', @targetdatafolder='c:\sql\data\', @targetlogfilder='c:\sql\logs\'; | |
select 'BACKUP DATABASE [' + name + '] TO DISK = ''' + @sourcebackupfolder + name | |
+ '.bak'' WITH INIT , NOUNLOAD , NAME = ''' + name + ''', NOSKIP , STATS = 100, NOFORMAT' | |
from sys.databases | |
where name not in ('master','msdb','model','tempdb'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add some functions (or override some functions) | |
// e.g. $(selector).autocomplete("doMore", data); | |
$.widget("ui.autocomplete", $.ui.autocomplete, { | |
doMore: function (data) { | |
// this = autocomplete object | |
// this.element = auto complete input element | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* thanks to http://stackoverflow.com/questions/18390574/how-to-delete-duplicate-rows-in-sql-server */ | |
/* partition on the columns that make the row unique */ | |
with dupes as ( | |
select *, rn = ROW_NUMBER() OVER (PARTITION BY col1, col2 ORDER BY col1) | |
from sources | |
) | |
delete from dupes | |
where rn > 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/questions/6930578/get-cursor-or-text-position-in-pixels-for-input-element/7948715#7948715 | |
function getTextBoundingRect(input, selectionStart, selectionEnd, debug) { | |
// Basic parameter validation | |
if (!input || !('value' in input)) return input; | |
if (typeof selectionStart == "string") selectionStart = parseFloat(selectionStart); | |
if (typeof selectionStart != "number" || isNaN(selectionStart)) { | |
selectionStart = 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TRIGGER [access_trigger] | |
ON ALL SERVER | |
with execute as 'sa' -- needed to query sys.dm_exec_connections table | |
FOR LOGON | |
AS | |
BEGIN | |
if original_login() not in ('superadmin', 'anothersuperadmin', 'mydomain\admin') | |
and exists ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @x xml = '<data UniqueID="1" Name="Bob"/><data UniqueID="2" Name="Joan"/>' | |
select * from dbo.fnu_XML_ToTable(@x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select o.type_desc type, o.name | |
from sys.OBJECTS o | |
left join sys.sql_expression_dependencies ref on ref.referenced_id = o.object_id | |
left join sys.OBJECTS o2 on o2.object_id = ref.referencing_id | |
where o2.name is null | |
and o.type_desc not in ('SYSTEM_TABLE','SQL_TRIGGER','INTERNAL_TABLE','SERVICE_QUEUE','TYPE_TABLE') | |
and o.type_desc not like '%CONSTRAINT%' | |
order by o.type_desc, o.name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @personid int = 1900, @start date = '2/24/2014', @stop date ='3/2/2014'; | |
merge people_schedules ps | |
using ( | |
select row_number() over ( partition by ps2.eventid, ps2.date order by ps2.uniqueid ) as row, ps2.uniqueid, ps2.personid, ps2.eventid, ps2.date, ps2.servicerequestid, | |
sum(ps3.labortimeregular) LaborTimeTotal, | |
from People_Schedules ps2 | |
join People_Schedules ps3 on ps2.eventid=ps3.eventid and ps2.personid=ps3.personid and ps2.date=ps3.date |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
files.physical_name, | |
files.name, | |
stats.num_of_writes, (1.0 * stats.io_stall_write_ms / stats.num_of_writes) avg_write_stall_ms, | |
stats.num_of_reads, (1.0 * stats.io_stall_read_ms / stats.num_of_reads) avg_read_stall_ms | |
FROM sys.dm_io_virtual_file_stats(2, NULL) as stats | |
JOIN master.sys.master_files AS files ON stats.database_id = files.database_id AND stats.file_id = files.file_id | |
WHERE files.type_desc = 'ROWS' | |
/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Formats a typical US phone number, including an extension (if preceeded by something like x, ex, ext, etc). | |
Crude but adequate. | |
*/ | |
String.prototype.formatPhone = function () { | |
var phone = this; | |
if (!phone) return ""; |