Quantcast
Browsing all 27 articles
Browse latest View live

Script to Strip Non Numeric Characters from string

Below sample script strips (removes) non numeric Characters from string (varchar) DECLARE @VARCHARString VARCHAR(8000) SET @VARCHARString = '000012W`''ASDASDS3A@!#@!#_)+)_4)' SELECT @VARCHARString...

View Article


sql server union with example

UNION : UNION Statement in SQL Server combines all rows in the results of two queries. EXAMPLE’s Given below: SELECT 1 UNION SELECT 2 Result: ———– 1 2 (2 row(s) affected) Result is the combining the...

View Article


sql server union order by clause

using union/union all with order by clause in sql server. In order to order the results of a union statement add order by clause with the column names corresponding to first select statement. If you...

View Article

truncate all tables sql server 2008

How to truncate all tables sql server? Following script truncates all the tables in SQL Server: DECLARE @tablename AS VARCHAR (1000) DECLARE @sql AS VARCHAR (1000) IF OBJECT_ID('tempdb.dbo.#tables') IS...

View Article

Group By Date Range – Examples

In many real time scenarios data is needed grouped by the date range for date (or) datetime columns. This post explains in detail as to how to group data over date range in sql server. Steps to group...

View Article


Group by Day – With Examples

How to Group by Day in sql server? Grouping By Day Of month: In order to group the data by day you can use sql server in built DAY() funtion. Grouping By Day Of week: For this you can use...

View Article

Group By Month, Year with example

In order to group by month you can use the SQL Server in built funtion Month(). GROUP BY MONTH([datetimecolumn]) TO group data by year you can use the in built funtion YEAR(). GROUP BY...

View Article

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: SELECT CAST( '2012-04-31'...

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 DECLARE @sql_handle AS VARBINARY (1000) SELECT @sql_handle = SQL_HANDLE FROM sys.sysprocesses WITH (NOLOCK) WHERE spid = 56; --To...

View Article

How to Find the List of Functions in SQL Server

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

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 SET NOCOUNT ON DECLARE @String VARCHAR(100) DECLARE @CorrectedString VARCHAR(100)...

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


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. Note that this script is solely for running on Development environments, do not run...

View Article


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
Browsing all 27 articles
Browse latest View live