devxlogo

SQL

Get Current Language ID

You can get the language ID with the following Select statement: SET LANGUAGE ‘French’SELECT @@LANGID AS ‘Language ID’

Write SQL Results to a Text file

You can write results of a SELECT query into a text file in the following way: master..xp_cmdshell ‘osql -S SERVERNAME -U USERNAME -P PASSWORD -Q “SELECT * FROM TABLE” -d

Diagnose System Slowdowns

One good way to quickly diagnose System slowdowns is to make use of the sp_who2 SQL function in the following way: EXEC sp_who2 This helps identify High CPU Usage, Blocking

Identify Tables Storing GUID Values

You can identify tables that store a GUID (Globally Unique Identifier) value with the following script: SELECT [table] = s.name + N’.’ + t.nameFROM sys.tables AS tINNER JOIN sys.schemas AS

Using sys.dm_db_missing_index_group_stats

Using sys.dm_db_missing_index_group_stats?returns summary information about groups of missing indexes, excluding spatial indexes. An example follows: SELECT TOP 5 * FROM sys.dm_db_missing_index_group_stats ORDER BY avg_total_user_cost * avg_user_impact * (user_seeks + user_scans)

Using the DATALENGTH SQL Function

The DATALENGTH SQL returns the length of columns in a table. SELECT length = DATALENGTH(ColumnName) FROM TableName ORDER BY ColumnName

Compress and Decompress SQL Functions

Compress: Compresses input data and returns the binary data of type VARBINARY(MAX) Decompress: Decompresses compressed input binary data and returns the binary data of type VARBINARY(MAX) Here is small example

Creating an HTML Table with SQL

You can create an HTML Table with SQL. You make use of the ‘FOR XML RAW’ and ‘FOR XML PATH’ statements to organize the Table Body (TBODY), Table Header (THEAD)