Export data from SQL Server to an Excel file


Sometimes you need to export data from SQL Server tables, views or the result of any T-SQL query into excel file, reason could be anything such as MIS team need Sales data in excel file…

 274 total views,  17 views today

Read More...

How to fetch alphanumeric string from table


Assume that you have a table which contains alphabetic, numeric, alphanumeric string, and special characters and you are asked to fetch only alphanumeric string from those strings. Following is the sample table named Numbers which…

 201 total views,  1 views today

Read More...

SET STATISTICS IO


SQL STATISTICS IO is a set statement , when it is enabled it causes SQL Server to display information about the amount of disk activity generated by T- SQL statement. SYTANX SET STATISTICS IO {…

 161 total views

Read More...

SQL Random Number


SQL RAND function is a mathematical function which returns a pseudo-random float value from 0 through 1, exclusive or a random value within any range. It can also take an optional seed parameter which is…

 433 total views,  3 views today

Read More...

How to insert the result of a stored procedure into table


Sometimes, you want to store the result of a stored procedure into table or temp table instead of returning the output. Storing output of stored procedure into table enables more option for you, such as…

 733 total views,  5 views today

Read More...

SQL Delete TOP


SQL delete statement is used to delete records from table based on specific conditions which are specified in where clause. Delete statement can also be used as Delete TOP, which also allows you to use…

 498 total views,  1 views today

Read More...

Date and Time Conversions in SQL Server


Sometimes you need to format a date in specific format such as format a date time string YYYY-MM-DD hh:mm:ss. mmm to date MM:DD:YY. SQL Server provides you a various options that you can use to…

 342 total views,  2 views today

Read More...

Print Christmas tree in SQL Server


Lets see how to print a Xmas or Christmas Tree in SQL Server. The best way of implementing a Xmas tree pattern you can use a Recursive CTE, as shown in below T-SQL. Note that:  After…

 269 total views,  5 views today

Read More...

SQL Code Snippets


SQL code snippet is a template which contains the basic structure of a Transact-SQL statement or block, so that you can quickly write queries without any syntax errors. It was released in SQL Server 2012…

 521 total views,  4 views today

Read More...

DROP IF EXISTS


SQL Server 2016 has released an optional IF EXISTS clause with DROP statement that can be used as DROP IF EXISTS. DROP IF EXITS verify if an object exists then drops an existing object and…

 340 total views,  1 views today

Read More...

Script table in SQL Server


You can script a table from database using a SQL Server Management Studio. SQL Server Management allows you to script out tables from database using a Script table as option. This option can be used…

 73 total views,  1 views today

Read More...

Table Value Constructor


Table Value Constructor (TVC) allows to group multiple rows of data in a single DML statement. It can be used as a part of either the VALUES clause of an INSERT INTO VALUES statement, or…

 305 total views

Read More...

IDENT_CURRENT Function


The IDENT_CURRENT function returns the last IDENTITY value generated for any specific table or view on an identity column in any session and any scope. This function is limited only to a specific table or…

 158 total views,  3 views today

Read More...

SQL ROLLBACK Transactions


SQL ROLLBACK transaction statement rolls back an explicit or implicit transaction to the beginning of the transaction. If savepoint is specified then it rolls back the transaction to a savepoint within the transaction. Basically, it…

 1,358 total views,  7 views today

Read More...

Separate numbers, letters and special characters from string


How to find and separate the numbers, letters and special characters from string? Suppose you a column in table which contains a mix words which may includes numbers, letters, and special characters, or either numbers…

 247 total views,  4 views today

Read More...

Column Level Encryption Decryption using Symmetric Keys


SQL Server allows several options to protect sensitive data, and one of them is specifying a column level encryption. Using this option you can encrypt a column data also decrypt the data. SQL Server encrypts data…

 460 total views,  4 views today

Read More...

SQL JSON_QUERY Function


SQL JSON_QUERY is a JSON function which extracts an object or an array from a JSON string. JSON_QUERY function introduced in SQL Server 2016. You can not extract a scalar value using JSON_QUERY function. It…

 294 total views,  1 views today

Read More...