Thursday, February 13, 2014

OPENQUERY() timeout error


Did you receive the following error while using an OPENQUERY() statement?

OLE DB provider “SQLNCLI1″ for linked server “[LinkedServerName]” returned message “Query timeout expired”.
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider “SQLNCLI1″ for linked server “[LinkedServerName]” reported an error. Execution terminated by the provider because a resource limit was reached.
Msg 7320, Level 16, State 2, Line 1
Cannot execute the query ”

Try adding a TOP clause,  example:
SELECT TOP 250000 * .....
If the error still occurs , increase the timeout settings in the Server Properties window or Linked Server Properties window.

Wednesday, January 15, 2014

Fetch Columns and datatypes from a given table


 The following query fetches  a list of all columns from the given table with their data types, data lengths and the  length of the longest value in that column


SELECT
   
    c.name 'Column Name',
    t.name 'Data type',
    c.max_length 'Max Length'

FROM  
    sys.columns c

INNER JOIN 
    sys.types t ON c.user_type_id = t.user_type_id

WHERE
    c.object_id = OBJECT_ID('tblName')

GROUP BY 
    Object_Name(c.object_id),
    c.name ,
    t.name ,
    c.max_length