Pages

Monday 30 December 2013

SQL SERVER – Order of Statement Execution

The order in which a query is written is not the order in which it is evaluated by SQL Server.
The query is evaluated by SQL server in following order:

5: SELECT   {select list}
1: FROM     {table source}
2: WHERE    {search condition}
3: GROUP BY {group by list}
4: HAVING   {search condition}
6: ORDER BY {order by list}

Sunday 17 February 2013

SQL SERVER - Search text inside SQL

We can find a text or a string inside SQL Server stored procedures / triggers / views / functions using the below function:


CREATE FUNCTION [dbo].[SearchObject]
(
    @str VARCHAR(100)
)
RETURNS TABLE 
RETURN
    SELECT 
        DISTINCT 
        QUOTENAME(s.name) + N'.' + QUOTENAME(o.name) AS ObjectFullName,
        s.name AS SchemaName,
        o.name AS ObjectName, 
        o.type_desc AS ObjectType
    FROM sys.objects o
    INNER JOIN syscomments c ON c.Id = o.object_id
    INNER JOIN sys.schemas s ON s.schema_id = o.schema_id
    WHERE 
    is_ms_shipped = 0 AND c.text like '%' + @str + '%'



SELECT * FROM [dbo].[SearchObject]('split')