Friday, 19 October 2012

#28 Replace di sql server

Berikut contoh simpel penggunaan replace di sql server:

select REPLACE
(
    path,
    (select path from MStructureOrganisation where id=(select parentid from MStructureOrganisation where id=128)),
    (select path from MStructureOrganisation where id=192)
)
from MStructureOrganisation where path like '0;0000375;0001099;0001099;0000542%'
Monday, 8 October 2012

#27. With di Sql Server

WITH n(IdCovJob, idemp, startdate, enddate) AS 
(
    select idcovjob, idemp, startdate, enddate
    from MCovjobemployee --where IdEmp='1576'
    union all
    SELECT x.idCovJob, n.idemp, x.activeddate, x.enddate
    FROM MCoverJob x WITH (NOLOCK), n
    WHERE n.IdCovJob = x.IdCovJobPar
)
insert into TempEmpCovjob (IdCovJob, idemp, startdate, enddate)
select * from (
    select * from n
)x