Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Everything / Languages / T-SQL

T-SQL

T-SQL

Great Reads

by Marian Placko
This article shows a simple hack of a built-in MS SQL Server WITH ENCRYPTION mechanism
by Snorri Kristjansson
A SQL server CLR Stored Procedure that can query the Active Directory directly in T-SQL code
by hector [.j.] rivas
Helping the combo box autocomplete function with a frequency count.
by mazhou
Ad-hoc pagination support with SQL Server codenamed “Denali”

Latest Articles

by Marian Placko
This article shows a simple hack of a built-in MS SQL Server WITH ENCRYPTION mechanism
by Snorri Kristjansson
A SQL server CLR Stored Procedure that can query the Active Directory directly in T-SQL code
by hector [.j.] rivas
Helping the combo box autocomplete function with a frequency count.
by mazhou
Ad-hoc pagination support with SQL Server codenamed “Denali”

All Articles

Sort by Score

T-SQL 

by Marian Placko
This article shows a simple hack of a built-in MS SQL Server WITH ENCRYPTION mechanism
by NightWizzard
Convert amounts to their spoken equivalents
by sandeepmittal11
Apply Operator in SQL Server
by Manjuke Fernando
How to give db_datareader access to a specific user across all the databases on a particular SQL Server
by Rob Branaghan
Just a function to make populating a datetime variable easier!
by André Kraak
This is an alternative for "Build a Date Function"
by Pranay Rana
CASE/WHEN return type
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...
by sandeepmittal11
COALESCE in SQL Server
by Homero Ibarra Ramírez
Tool on T-SQL to code basic generator for SQL Server
by Ahmad A.A. Ahmad
Combining MDX with T-SQL in One Result Set for SSRS (Hybrid Query)
by Pascal Ganaye
Provides a couple of hash functions (string to int) that will return the same value in C# and T-SQL
by Ashkan.hosseini
Stored procedure that generates insert stored procedure for tables
by markkang
This tip describes how to generate insert SQL statement from the records in an existing table in SQL server database
by saddam_msp
Shortcuts to execute your query faster while working or debugging T-SQL statement
by Bart Ducal
Universal data change tracking solution for auditing SQL Server databases
by Mel Padden
Default keyword in SQL Server
by Darek Danielewski
A small script to remove old user accounts
by Jovan Popovic(MSFT)
SQL Server 2016 introduces the new DROP IF EXISTS syntax
by Robby Tendean
How to create an efficient paging using SQL script
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...
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...
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);
by Liju Sankar
Find progress of a database restore using sys.dm_exec_requests
by Mehdy Moini
How to know which table is updated in the current logfile time.
by Muhammad Aqib Shehzad
Forgot Password and Email Check from Database
by Michael Selector
A code to declare a table variable which will be populated from a query
by Chetan Naithani
Stored Procedure to Generate Insert Scripts
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.
by Shamim Uddin
We will learn about hierarchical query in database with real example.
by Igor Krupitsky
Fast function that excludes weekends and holidays
by Daniel Miller
This tip shows how to display the length of the longest string value in every table and column in your database.
by Najmul Hoda
Here is the code snippet to check how many database connections are opened in SQL Server.
by E. Scott McFadden
This article explains how to create and use a self referencing key in a SQL Server Table.
by Ankur .K. Vishwakarma
This tip shows you a T/SQL function to split a string concatenated by a delimiter.
by Bhushan W. Juare
Passing calculated columns in the Where and Group by clause in T-SQL
by Bhushan W. Juare
This tip discusses how to perform pivot operations in T-SQL.
by O.Nasri
A good tutorial in how you can publish your ASP.NETCore MVC web application to IIS.
by Bhushan W. Juare
Removing SSAS(cube) dimension members using Except() function
by Satnam Singh CapGemini
Improving backup performance
by GuruprasadV
The trick shows how to generate the INSERT script for each line of table data
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 ----------------------------------------------------------------- --...
by Sarkis Matossian
The steps to install a CLR Stored Procedure in SQL Server
by Sarkis Matossian
Encoding a .NET assembly as a hex string to install in SQL Server.
by Herman.Instance
When using SqlDependency, is it possible that a detected change leads to 0 rows in the SqlDependency results?
by Satnam Singh CapGemini
Cannot Bulk Load Data Into the Table with Primary Key Constraint on it
by sandeepmittal11
Lead and Lag Functions in SQL Server
by Israel Cris Valenzuela
LTRIM and RTRIM don't always remove all the whitespace characters in a field such as carriage return or linefeed
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...
by Member 14691410
Providing admin with an alert mechanism via an SP
by User-12551084
Moving database file from one drive to another drive
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.
by Sumit Chawla
Describes how to parse and extract key value pairs from a string or column in SQL
by #realJSOP
It doesn't always happen the way you expect.
by Sifiso W Ndlovu
This tip illustrates a workaround to SQL Server pivoting on variable character data types.
by DrABELL
Portable solution encapsulated in single SQL query allows to select N rows offsetting M records
by Gene R. Browning
Generate random dates (and times if you like) for your test data environment.
by sandeepmittal11
Row_Number in SQL Server
by SonuKSingh
rowversion datatype in SQL Server: Track which row has been modified
by Evgeniy Sukhikh
Issues and solutions taken while moving R from cmd to sp_execute_external_script
by Luca Astolfi
User defined procedure for make an HTML table from T-SQL Select statment
by sandeepmittal11
A sequence is a user defined, schema bound object that generates a sequence of numeric values
by Paw Jershauge
An easy to use extendedproperty procedure (alternative to sp_dropextendedproperty, sp_addextendedproperty, sp_updateextendedproperty)
by Ngo Thanh Tung - Softech
T-SQL scripts: Write a table function to split a string with specific separator character
by Ksh_Sr
This tip shows how to separate a string with delimited characters.
by PIEBALDconsult
This is an alternative for "Split Any Delimited String in SQL"
by Srinivas-Miriyala
Executes SQL scripts in multiple databases at once.
by Simon Korenfeld
SQL schema with multi version tables support
by Nitinpatel
This SQL script will generate a script to drop and create all foreign keys in database.
by mkader
SQL scripts to insert File to BLOB field and export BLOB to File
by Dathuraj Pasarge
Extract SQL Server DB inventory\baseline using TSQL and PowerShell scripts
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.
by Michael Ecklin
This tip describes Microsoft SQL Server implementation of XIRR function.
by dmytro.sen
SQL to ADO.NET API (Automated ADO.NET)
by Bhushan W. Juare
Subquery in T-SQL
by brian_eckert
A proposed template for writing nested stored procedures that perform updates (inserts, updates, deletes)
by Pascal Ganaye
Reproducing the SQL RAND() function in C#
by Wendelius
TrimChar function which removes occurences of the desired character from both ends of a string.
by pankajupadhyay29
A nice way to get aggregated value without group by
by Miljan Radovic
T-SQL Simulator for Monty Hall Paradox
by Member 12574862
A new approach of calculating next N business days's date, provided we know the start date and the N number
by Antonino Porcino
How to use T-SQL function SCOPE_IDENTITY() to retrieve inserted rows identity values with CommandBuilders and DataAdapters
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.
by Deepak A S
An ALL SERVER trigger to know who it is!
by zvin
Splits string using TSQL, but a very simple technique using the XML datatype.