Quantcast
Channel: T-SQL Code Examples – SQLSERVERLEARNER
Browsing latest articles
Browse All 27 View Live

The conversion of a varchar data type to a datetime data type resulted in an...

When you try to convert varchar datatype to datetime you would get this error when the value in varchar datatype does not represent the correct range of date. Example Queries: [sql] SELECT CAST(...

View Article



How to call or execute a Stored Procedure from inside a Select Statement

How to call or execute a Stored Procedure from Select Statement in SQL Server? It is really simple to call a stored procedure from a select statement Using OPENROWSET. Below TSQL Query calls the...

View Article

TSQL Script to fetch the code that is executed by an SPID

Below is the TSQL Script to fetch the code that is executed by an SPID [sql] DECLARE @sql_handle AS VARBINARY (1000) SELECT @sql_handle = SQL_HANDLE FROM sys.sysprocesses WITH (NOLOCK) WHERE spid = 56;...

View Article

How to Find the List of Functions in SQL Server

Query to find the list of Functions in SQL Server [sql] SELECT name FROM sys.objects WHERE type IN (‘AF ‘,’FN’, ‘IF’, ‘TF’, ‘FS’, ‘FT’) [/sql]

View Article

Concatenating Data From Different Rows into Single Column Row

Consider a scenario where a table has multiple rows, and each of these rows belong to a group and the data from all the rows should be concatenated based on the group. This post explains different ways...

View Article


TSQL Script to remove TAB, LINE FEED and CARRIAGE RETURN

The below script removes the TAB(Horozontal Tab), Line feed(New line), Carriage Return Characters in a variable @String [sql] SET NOCOUNT ON DECLARE @String VARCHAR(100) DECLARE @CorrectedString...

View Article

Image may be NSFW.
Clik here to view.

Interesting Observation – Declaring Table Variables impact on Tempdb

Following was an intresting observation when creating table variables. 1. Table variables are created in tempdb. 2. Table variables are created in tempdb even before the declare table is called. Steps...

View Article

Impact of TEMPDB Collations on Other Databases

When you create databases with different collations then you have to be very careful when using the temporary tables. In the below script let us analyze such a scenario. Creating Sample database with...

View Article


Image may be NSFW.
Clik here to view.

HOW TO CONVERT TABLE DATA TO XML AND XML TO TABLE

HOW TO CONVERT TABLE DATA TO XML AND VICEVERSA. The below code explains how to convert the data in a table to xml form and then convert the xml back into table data. Creating sample table with data:...

View Article


TSQL Script to Clear SQL Server Cache

Below script that can be used to clear SQL Server Cache. Helpful while working on performance tuning of SQL Scripts. CHECKPOINT; GO DBCC DROPCLEANBUFFERS DBCC FREEPROCCACHE DBCC FREESYSTEMCACHE ('ALL')...

View Article
Browsing latest articles
Browse All 27 View Live




Latest Images