Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INSERT INTO [Terrorism].[FactAttack]
- SELECT *
- FROM (
- SELECT
- (
- SELECT TOP 1 location_id
- FROM [Terrorism].[DimLocation] loc
- WHERE
- loc.city = dest.city
- AND loc.country = dest.country
- AND loc.region = dest.region
- AND ABS(loc.latitude - latitude) < 0.0001
- AND ABS(loc.longtitude - longitude) < 0.0001
- ) location_id,
- (
- SELECT TOP 1 date_id
- FROM [Terrorism].[DimDate] dat
- WHERE
- dat.[day] = dest.[day]
- AND dat.[month] = dest.[month]
- AND dat.[year] = dest.[year]
- ) date_id,
- (
- SELECT TOP 1 target_group_id
- FROM [Terrorism].[DimTargetGroup] tar
- WHERE tar.target_group_name = dest.targetype
- ) target_group_id,
- (
- SELECT TOP 1 terrorist_group_id
- FROM [Terrorism].[DimTerroristGroup] ter
- WHERE ter.terrorist_group_name = dest.[group]
- ) terrorist_group_id,
- (
- SELECT TOP 1 weapon_type_id
- FROM [Terrorism].[DimWeaponType] weap
- WHERE weap.weapon_type_name = dest.weapontype
- ) weapon_type_id,
- wounded,
- killed
- FROM [Terrorism].[dbo].[OLE DB Destination] dest
- ) inp
- WHERE NOT EXISTS (
- SELECT *
- FROM [Terrorism].[FactAttack] fa
- WHERE
- fa.date_id = inp.date_id
- AND (fa.location_id = inp.location_id
- OR (fa.location_id IS NULL AND inp.location_id IS NULL))
- AND (fa.target_group_id = inp.target_group_id
- OR (fa.target_group_id IS NULL AND inp.target_group_id IS NULL))
- AND (fa.terrorist_group_id = inp.terrorist_group_id
- OR (fa.terrorist_group_id IS NULL AND inp.terrorist_group_id IS NULL))
- AND (fa.weapon_type_id = inp.weapon_type_id
- OR (fa.weapon_type_id IS NULL AND inp.weapon_type_id IS NULL))
- AND (fa.injured_count = inp.wounded
- OR (fa.injured_count IS NULL AND inp.wounded IS NULL))
- AND (fa.killed_count = inp.killed
- OR (fa.killed_count IS NULL AND inp.killed IS NULL))
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement