Demo entry 6761919

Insert

   

Submitted by anonymous on Oct 08, 2018 at 08:44
Language: SQL. Code size: 711 Bytes.

with cte as (

select em.*, rank() over (partition by em.eventId order by em.DateCreated asc) as ranking, c.SportID
from EventMetadata em (nolock)
left join Event e (nolock) ON e.EventID = em.EventID
INNER JOIN Competition c ON c.CompetitionID = em.CompetitionID
where em.DateCreated > $DATE$
and e.EventID is null
)

-- UNCOMMEN THE FOLLOWING LINE TO ACTUALLY INSERT DATA INTO dbo.[Event]

--insert into [Event]
select em.EventId, em.SportID, em.CompetitionID, em.HomeTeamID, em.AwayTeamID,  em.EventDate, em.EventStage, em.IsGround, 0 as IsClosed,  em.IsLive, SYSDATETIMEOFFSET() as DateCreated, SYSDATETIMEOFFSET() as DateUpdated, 'Dev' createdBy, 'Dev' UpdatedBy
from cte em
where ranking = 1

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).