Thursday, 8 September 2016

sp_helptext for views

SELECT DEFINITION

FROM sys.sql_modules
WHERE object_id = OBJECT_ID('dw.v_hrg_v4_201213_Ip_Input')

Thursday, 4 August 2016

TSQL - Comparing DateTime

  Convert(varchar(6),dischargedate,112) between '201604' and '201703'

Wednesday, 20 July 2016

Tuesday, 19 July 2016

SQL Server - drop an index if exists

if exists (select name from sysindexes where name = 'pk_apc_scg')
  drop index tbl_apc_scg.pk_apc_scg

SQL Server - How to create a view with an index

Creating views with index

create view vw_ukhd_english_postcodes
WITH SCHEMABINDING as
  select
    Char_8_ASCII_Index
  from
    ODS.Postcode_Grid_Refs_Eng_Wal_Sco_And_NI_SCD
  where
    is_latest = 1
    and substring(country, 1,1) = 'E'

create unique clustered index pk_ukhd_country on vw_ukhd_english_postcodes(Char_8_ASCII_Index)

SQL Server - How to create a view with an index

Creating views with index

create view vw_ukhd_english_postcodes
WITH SCHEMABINDING as
  select
    Char_8_ASCII_Index
  from
    ODS.Postcode_Grid_Refs_Eng_Wal_Sco_And_NI_SCD
  where
    is_latest = 1
    and substring(country, 1,1) = 'E'

create unique clustered index pk_ukhd_country on vw_ukhd_english_postcodes(Char_8_ASCII_Index)