Tips & Tricks
Everything you ever wanted to know but never dared to search for...

Otherwise explicitly stated the given examples have been tested using Microsoft SQL Server.

Get SQL Version

SELECT @@VERSION

Use different value in a SELECT when data is NULL

ISNULL(DB_Variable, '*empty*') 

Show SQL grant permissions

SELECT class_desc
     , CASE WHEN class = 0 THEN DB_NAME()
            WHEN class = 1 THEN OBJECT_NAME(major_id)
            WHEN class = 3 THEN SCHEMA_NAME(major_id) END [Securable]
     , USER_NAME(grantee_principal_id) [User]
     , permission_name
     , state_desc
FROM sys.database_permissions

Handy SQL functions

SUBSTRING(path,2,10)
CHARINDEX('\data', path)
LEN(path)

Gaetano Causio © | Privacy Policy | Disclaimer