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
-- Current date and time | |
PRINT GETDATE(); | |
-- Same as GETDATE but ANSI-SQL-compliant | |
PRINT CURRENT_TIMESTAMP; | |
-- Current date and time in UTC | |
PRINT GETUTCDATE(); | |
-- Current date and time |
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
USE TSQL2012; | |
-- Adjusts the given DATETIMEOFFSET value: | |
PRINT SWITCHOFFSET(SYSDATETIMEOFFSET(), '+02:00'); | |
-- Takes a date and time that is not offset aware | |
-- and produces a DATETIMEOFFSET value: | |
PRINT TODATETIMEOFFSET(CURRENT_TIMESTAMP, '+01:00') | |
-- Add a specified number of units to an input |
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
USE TSQL2012; | |
-- Catalog Views | |
SELECT | |
SCHEMA_NAME(schema_id) AS schema_name, | |
name AS table_name, | |
CONCAT(SCHEMA_NAME(schema_id) + '.', name) AS full_name | |
FROM sys.tables; | |
SELECT |
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 FUNCTION dbo.fn_swag(@Number AS INT) | |
RETURNS INT | |
AS | |
BEGIN | |
RETURN @Number | |
END | |
GO | |
SELECT dbo.fn_swag(10); |
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 FUNCTION dbo.GETAGE( | |
@DOB DATETIME | |
) | |
RETURNS INT | |
WITH SCHEMABINDING | |
AS | |
BEGIN | |
DECLARE @iMonthDayDob INT | |
DECLARE @iMonthDayPassedDate INT |
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
public class AdoBookmarkRepository : IBookmarkRepository, IDisposable | |
{ | |
private readonly SqlCeConnection _connection; | |
public AdoBookmarkRepository(SqlCeConnection connection) | |
{ | |
if (connection == null) | |
throw new ArgumentNullException("connection"); | |
if (connection.State == ConnectionState.Closed) |
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
public sealed class BookmarkRepository : IBookmarkRepository, IDisposable | |
{ | |
private readonly BookmarksContext _bookmarksContext; | |
public BookmarkRepository(IDbConnection connection) | |
{ | |
if (connection == null) | |
throw new ArgumentNullException("connection"); | |
if (connection.State == ConnectionState.Closed) |
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
public static class CompactDatabase | |
{ | |
public const string ConnectionString = "Data Source=Bookmarks.sdf;"; | |
public static void Setup() | |
{ | |
if (File.Exists("Bookmarks.sdf")) | |
return; | |
using (var engine = new SqlCeEngine(ConnectionString)) |
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
public static class MethodInvoker | |
{ | |
public static object InvokeMethod(string methodName, object[] paramaters = null) | |
{ | |
MethodInfo method = ResolveMethodWithName(methodName); | |
if (method == null) | |
throw new InvalidOperationException("A method with the name " + methodName + " cannot be found."); | |
if (method.IsStatic) | |
{ |
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 | |
c.displayname, | |
SUM(length(body_xml) - length(replace(body_xml, ' ', '')) + 1) AS numwords | |
FROM Messages AS m | |
LEFT OUTER JOIN Contacts AS c | |
ON m.author = c.skypename | |
WHERE m.convo_id = 197156 | |
AND m.body_xml IS NOT NULL AND c.displayname <> '' | |
GROUP BY m.author | |
ORDER BY numwords DESC |