but!... comming soon!

About Techinforoad.com

Welcome to Techinforoad.com - my website where I will publish various articles, tutorials and how-tos on Microsoft Business Solutions Dynamics NAV, SQL Server, virtualization technology and more.
Snippets
Here I have a collection of some usefull T-SQL snippets.


Check database existence
User Rating: / 1
PoorBest 

This query verifies if the certain database exists on server or not

 

T-SQL

SELECT 'Exists' From Information_schema.Schemata
WHERE
Catalog_name='AdventureWorks'

 

 
Use one IF...ELSE block
User Rating: / 1
PoorBest 
Remarks

IF...ELSE constructs can be used in batches, in stored procedures (in which these constructs are often used to test for the existence of some parameter), and in ad hoc queries.

IF tests can be nested after another IF or following an ELSE. There is no limit to the number of nested levels.

Examples
Use one IF...ELSE block

This example shows an IF condition with a statement block. If the average price of the title is not less than $15, it prints the text: Average title price is more than $15.

T-SQL

USE pubs
GO

IF (SELECT AVG(price) FROM titles WHERE type = 'mod_cook') < $15
BEGIN
PRINT 'The following titles are excellent mod_cook books:'
PRINT ' '
SELECT SUBSTRING(title, 1, 35) AS Title
FROM titles
WHERE
type = 'mod_cook'

END

ELSE
IF (SELECT AVG(price) FROM titles WHERE type = 'mod_cook') > $15
BEGIN
PRINT 'The following titles are expensive mod_cook books:'
PRINT ' '
SELECT SUBSTRING(title, 1, 35) AS Title
FROM titles
WHERE type = 'mod_cook'
END

Origin: MSDN