sel
  w.cal_dt,
  w.nt_login,
  case when ldap.uid is not null then 2
       else 1 end as user_batch_ind,
  case when user_batch_ind=1 then 8
       else coalesce(p.user_persona_id,1) end as user_persona_id,
  asset.fe_asset_id,
  asset.fe_asset_name,
  asset.fe_asset_alias_name,
  1 as fe_asset_type_cd,
  asset.prdctn_ind,
  6  as pltfrm_id, 
  w.prjct_id,
  asset.leaf_team_id,
  asset.cert_ind,
  asset.cert_dt,
  asset.prdct_id,
  asset.src_cre_nt_login,
  w.access_cnt
from ddm_data_assets_w.ds_tableau_rpt_usage_dtl_w w
join (select a.*,row_number() over (partition by lctn_txt order by src_cre_dt desc) as rn from ddm_data_assets_t.ds_fe_asset a) asset
on w.lctn_txt=asset.lctn_txt
and asset.pltfrm_id=6 
and asset.rn=1
left join 
 ( select uid from corp_hr_v.ldap_emply
   group by 1) ldap
on w.nt_login=ldap.uid
left join ddm_ram_t.ds_user_persona_info_hist p
on w.nt_login=p.nt_login
and w.cal_dt>=p.start_dt
and w.cal_dt<p.end_dt
where w.cal_dt>=cast('20151023' as date format 'yyyymmdd') - 5
and w.cal_dt<cast('20151024' as date format 'yyyymmdd')
--------------------
SELECT w.cal_dt, w.nt_login
	, CASE
		WHEN ldap.uid IS NOT NULL THEN 2
		ELSE 1
	END AS user_batch_ind
	, CASE
		WHEN user_batch_ind = 1 THEN 8
		ELSE coalesce(p.user_persona_id, 1)
	END AS user_persona_id, asset.fe_asset_id, asset.fe_asset_name, asset.fe_asset_alias_name, 1 AS fe_asset_type_cd
	, asset.prdctn_ind, 6 AS pltfrm_id, w.prjct_id, asset.leaf_team_id, asset.cert_ind
	, asset.cert_dt, asset.prdct_id, asset.src_cre_nt_login, w.access_cnt
FROM ddm_data_assets_w.ds_tableau_rpt_usage_dtl_w w
	JOIN (
		SELECT a.*, row_number() OVER (PARTITION BY lctn_txt ORDER BY src_cre_dt DESC) AS rn
		FROM ddm_data_assets_t.ds_fe_asset a
	) asset
	ON w.lctn_txt = asset.lctn_txt
		AND asset.pltfrm_id = 6
		AND asset.rn = 1
	LEFT JOIN (
		SELECT uid
		FROM corp_hr_v.ldap_emply
		GROUP BY 1
	) ldap
	ON w.nt_login = ldap.uid
	LEFT JOIN ddm_ram_t.ds_user_persona_info_hist p
	ON w.nt_login = p.nt_login
		AND w.cal_dt >= p.start_dt
		AND w.cal_dt < p.end_dt
WHERE w.cal_dt >= CAST('20151023' AS date FORMAT 'yyyymmdd') - 5
	AND w.cal_dt < CAST('20151024' AS date FORMAT 'yyyymmdd')
------------------------------------------------------------------------------------------------------------------------
SELECT WITH DELETED ROWS COUNT(*) FROM  ldi_table
--------------------
SELECT WITH DELETED ROWS COUNT(*)
FROM ldi_table
------------------------------------------------------------------------------------------------------------------------
SELECT AS JSON a, b, j FROM MyTable
--------------------
SELECT AS JSON a, b, j
FROM MyTable
------------------------------------------------------------------------------------------------------------------------
SELECT NORMALIZE ON MEETS OR OVERLAPS emp_id, duration
     FROM project
--------------------
SELECT NORMALIZE ON MEETS OR OVERLAPS emp_id, duration
FROM project
------------------------------------------------------------------------------------------------------------------------
SELECT NORMALIZE project_name, duration
FROM project
--------------------
SELECT NORMALIZE project_name, duration
FROM project
------------------------------------------------------------------------------------------------------------------------
SELECT TOP 10 *
     FROM orders
--------------------
SELECT TOP 10 *
FROM orders
------------------------------------------------------------------------------------------------------------------------
CREATE VOLATILE MULTISET TABLE TMP_MEMBER_INFO2
(
  MBR_CARD_NBR VARCHAR(50),
  MBR_CARD_NBR_OLD VARCHAR(50),
  CUST_NBR CHAR(50) ,         
  NM VARCHAR(50) ,
  ID_CARD VARCHAR(20) ,
  ID_CARD_FLAG VARCHAR(20) ,
  SEX_CD VARCHAR(20) ,
  HMTON_CD VARCHAR(20) ,
  BIRTH_DT_OLD DATE FORMAT 'YYYY-MM-DD' ,
  BIRTH_DT DATE FORMAT 'YYYY-MM-DD' ,
  REG_TM TIMESTAMP(0) ,
  CONTACT_TEL VARCHAR(20) ,
  HOME_ADDR VARCHAR(100) ,
  AFFL_SITE_ID VARCHAR(100) ,
  AFFL_BUSI_DIST_CD VARCHAR(20) ,
  BUSI_DIST_DISTANCE_CD VARCHAR(20) ,
  COMBINE_TYPE VARCHAR(20),
  COMBINE_SEQ INTEGER ,
  ONLINE_REG_FLAG VARCHAR(2) ,
  ACTIVE_FLAG VARCHAR(2),
	BIZ_SPACE_ID VARCHAR(40),
	BIZ_SPACE_NAME VARCHAR(64),
	BIZ_SPACE_CODE VARCHAR(40),
  DATA_UPD_TM TIMESTAMP(0),
  COMBINE_SEQ2 INTEGER,
  REG_CHANNEL_CODE VARCHAR(32),
  REG_CHANNEL_NAME VARCHAR(64)
)
PRIMARY INDEX ( MBR_CARD_NBR , MBR_CARD_NBR_OLD , BIZ_SPACE_CODE , CUST_NBR , BIZ_SPACE_ID )
ON COMMIT PRESERVE ROWS
--------------------
CREATE TABLE TMP_MEMBER_INFO2 (
	MBR_CARD_NBR VARCHAR(50),
	MBR_CARD_NBR_OLD VARCHAR(50),
	CUST_NBR CHAR(50),
	NM VARCHAR(50),
	ID_CARD VARCHAR(20),
	ID_CARD_FLAG VARCHAR(20),
	SEX_CD VARCHAR(20),
	HMTON_CD VARCHAR(20),
	BIRTH_DT_OLD DATE FORMAT 'YYYY-MM-DD',
	BIRTH_DT DATE FORMAT 'YYYY-MM-DD',
	REG_TM TIMESTAMP(0),
	CONTACT_TEL VARCHAR(20),
	HOME_ADDR VARCHAR(100),
	AFFL_SITE_ID VARCHAR(100),
	AFFL_BUSI_DIST_CD VARCHAR(20),
	BUSI_DIST_DISTANCE_CD VARCHAR(20),
	COMBINE_TYPE VARCHAR(20),
	COMBINE_SEQ INTEGER,
	ONLINE_REG_FLAG VARCHAR(2),
	ACTIVE_FLAG VARCHAR(2),
	BIZ_SPACE_ID VARCHAR(40),
	BIZ_SPACE_NAME VARCHAR(64),
	BIZ_SPACE_CODE VARCHAR(40),
	DATA_UPD_TM TIMESTAMP(0),
	COMBINE_SEQ2 INTEGER,
	REG_CHANNEL_CODE VARCHAR(32),
	REG_CHANNEL_NAME VARCHAR(64)
)
PRIMARY INDEX (MBR_CARD_NBR, MBR_CARD_NBR_OLD, BIZ_SPACE_CODE, CUST_NBR, BIZ_SPACE_ID)
ON COMMIT PRESERVE ROWS
------------------------------------------------------------------------------------------------------------------------
SELECT
  MBR_CARD_NBR , '' AS CUST_NBR , NM , ID_CARD , ID_CARD_FLAG , SEX_CD , HMTON_CD , BIRTH_DT_OLD , BIRTH_DT
, REG_TM , CONTACT_TEL , HOME_ADDR , AFFL_SITE_ID , AFFL_BUSI_DIST_CD , BUSI_DIST_DISTANCE_CD , ONLINE_REG_FLAG , ACTIVE_FLAG
, REG_CHANNEL_CODE , REG_CHANNEL_NAME
FROM D_MEMBER_INFO_TMP_NEW
WHERE LENGTH(MBR_CARD_NBR) >= 12
QUALIFY ROW_NUMBER() OVER(PARTITION BY MBR_CARD_NBR ORDER BY BIZ_SPACE_CODE DESC)=1
--------------------
SELECT MBR_CARD_NBR, '' AS CUST_NBR, NM, ID_CARD, ID_CARD_FLAG
	, SEX_CD, HMTON_CD, BIRTH_DT_OLD, BIRTH_DT, REG_TM
	, CONTACT_TEL, HOME_ADDR, AFFL_SITE_ID, AFFL_BUSI_DIST_CD, BUSI_DIST_DISTANCE_CD
	, ONLINE_REG_FLAG, ACTIVE_FLAG, REG_CHANNEL_CODE, REG_CHANNEL_NAME
FROM D_MEMBER_INFO_TMP_NEW
WHERE LENGTH(MBR_CARD_NBR) >= 12
QUALIFY ROW_NUMBER() OVER (PARTITION BY MBR_CARD_NBR ORDER BY BIZ_SPACE_CODE DESC) = 1
