Script SQL Server

HTML Query Result format

    SET @tableHTML = N'<table>' + N'<tr><th>SpecialOfferID</th> <th>Description</th> <th>Type</th> <th>Category</th> <th>StartDate</th> <th>EndDate</th> </tr>' + CAST ( ( SELECT td =...

FREEPROCCACHE - Execution Plans

To clean up the execution plan:   -- Example 3 (Scalpel) -- Remove one plan from the cache -- Get the plan handle for a cached plan SELECT cp.plan_handle, st.[text] FROM sys.dm_exec_cached_plans AS cp CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st WHERE [text] LIKE...

SQL Split 2014

Select PARSENAME(replace('/Transport/Bus-Accessories/Air-Conditioning','/','.'), 2)

Date Conversion

  First Day Of Current Week.   select CONVERT(varchar,dateadd(week,datediff(week,0,getdate()),0),106) Last Day Of Current Week.   select CONVERT(varchar,dateadd(week,datediff(week,0,getdate()),6),106) First Day Of Last week.   select...

Shows up the last backup restored

WITH lastrestores       AS (SELECT DatabaseName = [d].[name],                  [d].[create_date],           &n

Função apenas Número / Function Only integer

CREATE FUNCTION dbo.Fnonlyint (@Text VARCHAR(8000))  /*****************************************************************************  Name:  dbo.fnOnlyInt  Considers only the numbers.  *************************************************

Query Result in a single line / Resultado em uma linha

SELECT NAME + ', '  FROM   sysobjects  FOR xml path('') 

Reading XML Column

    Example 02 ------------------------------------- <ArrayOfCustomers xmlns:xsd="https://www.w3.org/2001/XMLSchema"                          ...

Reading XML Column

DECLARE    @x XMLSET @x = '<CategoryDetails xmlns="https://api.trademe.co.nz/v1">   <CategoryId>DW3085</CategoryId>   <Name>Dredging</Name>  ...

SSRS - Subscription

SELECT USR.username      AS SubscriptionOwner,         SUB.modifieddate,         SUB.[description],         SUB.eventtype,    

<< 2 | 3 | 4 | 5 | 6 >>