Click here to Skip to main content
15,886,873 members
Everything / Programming Languages / T-SQL

T-SQL

T-SQL

Great Reads

by dale.newman
Google your SQL.
by honey the codewitch
Embed fast streaming C# code to match text based on inputted regular expressions
by DaveDavidson
In this article, I show LINQ to Entities syntax that will produce queries with CROSS APPLY and LEFT OUTER JOIN clauses.
by Ed Wiebe
Can't we obtain the benefit of using bitwise operators for SQL many-to-many relationships AND maintain referential integrity?

Latest Articles

by Federico Di Marco
spSearchTables: a helper T-SQL stored procedure for digging into (large) databases
by Dathuraj Pasarge
Extract SQL Server DB inventory\baseline using TSQL and PowerShell scripts
by Sergei Y.Kitáev
Introduction to statically parameterized SQL language
by honey the codewitch
Embed fast streaming C# code to match text based on inputted regular expressions

All Articles

Sort by Title

T-SQL 

27 Mar 2012 by Marian Placko
This article shows a simple hack of a built-in MS SQL Server WITH ENCRYPTION mechanism
18 Dec 2016 by NightWizzard
Convert amounts to their spoken equivalents
16 Nov 2015 by sandeepmittal11
Apply Operator in SQL Server
10 Sep 2018 by Manjuke Fernando
How to give db_datareader access to a specific user across all the databases on a particular SQL Server
23 Nov 2012 by Rob Branaghan
Just a function to make populating a datetime variable easier!
26 Nov 2012 by André Kraak
This is an alternative for "Build a Date Function"
7 Dec 2010 by Pranay Rana
CASE/WHEN return type
24 Nov 2010 by Morten Nilsen
Unless you are placing this code in a stored procedure, you could just as well do this:SELECT *FROM ( SELECT 'A1' AS String1,'B1' AS String2, GETDATE() AS DateCol UNION ALL SELECT 'A2','B2', GETDATE()) AS dORDER BY And then append the sanitized column name to sort...
15 Nov 2015 by sandeepmittal11
COALESCE in SQL Server
8 Jan 2020 by Homero Ibarra Ramírez
Tool on T-SQL to code basic generator for SQL Server
27 Sep 2014 by Ahmad A.A. Ahmad
Combining MDX with T-SQL in One Result Set for SSRS (Hybrid Query)
26 Oct 2011 by Pascal Ganaye
Provides a couple of hash functions (string to int) that will return the same value in C# and T-SQL
26 Sep 2013 by Ashkan.hosseini
Stored procedure that generates insert stored procedure for tables
8 Mar 2016 by markkang
This tip describes how to generate insert SQL statement from the records in an existing table in SQL server database
31 Jan 2017 by saddam_msp
Shortcuts to execute your query faster while working or debugging T-SQL statement
29 Jan 2017 by Bart Ducal
Universal data change tracking solution for auditing SQL Server databases
12 Jun 2011 by Mel Padden
Default keyword in SQL Server
16 Jan 2016 by Darek Danielewski
A small script to remove old user accounts
3 Nov 2015 by Jovan Popovic(MSFT)
SQL Server 2016 introduces the new DROP IF EXISTS syntax
16 Jan 2012 by Robby Tendean
How to create an efficient paging using SQL script
28 Dec 2011 by NeoPunk
Hi, what about such solution?DECLARE @pageNumber INTDECLARE @rowsOnPage INTSET @rowsOnPage=5SET @pageNumber=2DECLARE @totalItemsToSelect INTSET @totalItemsToSelect=@rowsOnPage * @pageNumberSELECT TOP (@rowsOnPage) * FROM MainTrans WHERE ID IN( SELECT TOP...
10 Jan 2012 by jeantoledo
Take a look at this:DECLARE @ActualRow = 1; /*Start in first item*/DECLARE @ItensCount = 100; /*100 itens for page*/DECLARE @Page = 1; /*Start in first page*/SELECT * FROM(SELECT *, ROWNUMBER() OVER(ORDER BY Name) as ROWNUM FROM Users) as UsWHERE ROWNUM BETWEEN...
10 Jan 2012 by kamiktk123
string Query = string.Format(@"SELECT * FROM (SELECT *, " + @"ROW_NUMBER() OVER(ORDER BY PRODUCT_ID DESC ) AS ROW_NUM FROM({0}) " + @"AS TEMP_INNER) AS TEMP_OUTER WHERE ROW_NUM BETWEEN '{1}' AND " + @"({2} + {3}) - 1", strSql, startRowIndex, startRowIndex, maximumRows);
15 Jan 2015 by Liju Sankar
Find progress of a database restore using sys.dm_exec_requests
12 Sep 2013 by Mehdy Moini
How to know which table is updated in the current logfile time.
22 Oct 2013 by Muhammad Aqib Shehzad
Forgot Password and Email Check from Database
14 Jul 2015 by Michael Selector
A code to declare a table variable which will be populated from a query
11 Dec 2017 by Chetan Naithani
Stored Procedure to Generate Insert Scripts
3 Jan 2014 by Sergii Syrovatchenko
This tip describes the most convenient way of process automation of generating HTML reports for dynamic table-structures and sending them to different people.
27 Aug 2016 by Shamim Uddin
We will learn about hierarchical query in database with real example.
6 Nov 2020 by Igor Krupitsky
Fast function that excludes weekends and holidays
22 Nov 2015 by Daniel Miller
This tip shows how to display the length of the longest string value in every table and column in your database.
13 Nov 2015 by Najmul Hoda
Here is the code snippet to check how many database connections are opened in SQL Server.
8 Jan 2020 by E. Scott McFadden
This article explains how to create and use a self referencing key in a SQL Server Table.
14 Apr 2014 by Ankur .K. Vishwakarma
This tip shows you a T/SQL function to split a string concatenated by a delimiter.
13 Jun 2013 by Bhushan W. Juare
Passing calculated columns in the Where and Group by clause in T-SQL
16 Jun 2013 by Bhushan W. Juare
This tip discusses how to perform pivot operations in T-SQL.
1 Nov 2016 by O.Nasri
A good tutorial in how you can publish your ASP.NETCore MVC web application to IIS.
16 Jun 2013 by Bhushan W. Juare
Removing SSAS(cube) dimension members using Except() function
1 Oct 2018 by Satnam Singh CapGemini
Improving backup performance
5 Jan 2011 by GuruprasadV
The trick shows how to generate the INSERT script for each line of table data
6 Jul 2011 by Deep In The Code
IF OBJECT_ID('sysGenerateInsert','P') IS NOT NULLBEGIN DROP PROC sysGenerateInsert PRINT 'sysGenerateInsert SP successfully dropped'END GO CREATE PROC sysGenerateInsert(@TblName varchar(128))ASBEGIN ----------------------------------------------------------------- --...
15 Jul 2015 by Sarkis Matossian
The steps to install a CLR Stored Procedure in SQL Server
30 Nov 2015 by Sarkis Matossian
Encoding a .NET assembly as a hex string to install in SQL Server.
21 May 2019 by Herman<T>.Instance
When using SqlDependency, is it possible that a detected change leads to 0 rows in the SqlDependency results?
11 Jul 2018 by Satnam Singh CapGemini
Cannot Bulk Load Data Into the Table with Primary Key Constraint on it
23 Feb 2016 by sandeepmittal11
Lead and Lag Functions in SQL Server
18 Feb 2012 by Israel Cris Valenzuela
LTRIM and RTRIM don't always remove all the whitespace characters in a field such as carriage return or linefeed
16 Feb 2012 by PIEBALDconsult
In SQL Server 2008, I do that with a CLR User Defined Function:namespace PIEBALD.Lib{ public static partial class LibSql { public static string Trim ( string Victim ) { return ( Victim.Trim() ) ; } }}Needs to be built into a...
2 Sep 2021 by Member 14691410
Providing admin with an alert mechanism via an SP
17 Oct 2018 by User-12551084
Moving database file from one drive to another drive
4 Dec 2011 by GuruprasadV
Check if dependency of a table are objects referenced by a stored proc. A system table with CTE can help to identify dependency quickly.
7 Jul 2012 by Sumit Chawla
Describes how to parse and extract key value pairs from a string or column in SQL
22 Sep 2017 by #realJSOP
It doesn't always happen the way you expect.
22 Feb 2016 by Sifiso W Ndlovu
This tip illustrates a workaround to SQL Server pivoting on variable character data types.
15 Aug 2012 by DrABELL
Portable solution encapsulated in single SQL query allows to select N rows offsetting M records
13 May 2017 by Evgeniy Sukhikh
Issues and solutions taken while moving R from cmd to sp_execute_external_script
25 Aug 2016 by Gene R. Browning
Generate random dates (and times if you like) for your test data environment.
17 Nov 2015 by sandeepmittal11
Row_Number in SQL Server
19 Oct 2013 by SonuKSingh
rowversion datatype in SQL Server: Track which row has been modified
2 Feb 2018 by Luca Astolfi
User defined procedure for make an HTML table from T-SQL Select statment
23 Nov 2015 by sandeepmittal11
A sequence is a user defined, schema bound object that generates a sequence of numeric values
29 Dec 2016 by Paw Jershauge
An easy to use extendedproperty procedure (alternative to sp_dropextendedproperty, sp_addextendedproperty, sp_updateextendedproperty)
18 Jun 2014 by Ngo Thanh Tung - Softech
T-SQL scripts: Write a table function to split a string with specific separator character
11 Sep 2015 by Ksh_Sr
This tip shows how to separate a string with delimited characters.
11 Sep 2015 by PIEBALDconsult
This is an alternative for "Split Any Delimited String in SQL"
13 Nov 2010 by Srinivas-Miriyala
Executes SQL scripts in multiple databases at once.
14 Jul 2016 by Simon Korenfeld
SQL schema with multi version tables support
7 Mar 2014 by Nitinpatel
This SQL script will generate a script to drop and create all foreign keys in database.
24 Apr 2012 by mkader
SQL scripts to insert File to BLOB field and export BLOB to File
8 May 2023 by Dathuraj Pasarge
Extract SQL Server DB inventory\baseline using TSQL and PowerShell scripts
27 May 2016 by Shashangka Shekhar
In this post, we will create a new user in SQL Server Management Studio (SSMS) & allow access to that user to perform a specific operation.
8 Jul 2016 by Michael Ecklin
This tip describes Microsoft SQL Server implementation of XIRR function.
10 Apr 2017 by dmytro.sen
SQL to ADO.NET API (Automated ADO.NET)
16 Jun 2013 by Bhushan W. Juare
Subquery in T-SQL
2 May 2011 by pankajupadhyay29
A nice way to get aggregated value without group by
30 Nov 2015 by Miljan Radovic
T-SQL Simulator for Monty Hall Paradox
10 Jun 2016 by Member 12574862
A new approach of calculating next N business days's date, provided we know the start date and the N number
24 Jun 2015 by brian_eckert
A proposed template for writing nested stored procedures that perform updates (inserts, updates, deletes)
8 Feb 2012 by Pascal Ganaye
Reproducing the SQL RAND() function in C#
30 Sep 2016 by Wendelius
TrimChar function which removes occurences of the desired character from both ends of a string.
23 Nov 2011 by Antonino Porcino
How to use T-SQL function SCOPE_IDENTITY() to retrieve inserted rows identity values with CommandBuilders and DataAdapters
18 Aug 2016 by Michael Ecklin
Sometimes, we need to compare 2 tables to see what was changed. This tip shows you 2 different ways to compare data.
1 Feb 2016 by Deepak A S
2 Oct 2011 by zvin
Splits string using TSQL, but a very simple technique using the XML datatype.