Created
May 3, 2011 00:01
-
-
Save mamcx/952601 to your computer and use it in GitHub Desktop.
Esquema inicial pasar ciudades de agenda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Migracion de Agenda a | |
-- AdventureWorks R2 | |
USE AdventureWorks | |
-- Ejecutar solo una vez, para hacer que la BD sea compatible con el | |
-- COLLATE por defecto de SQL SERVER (Mirar primero SELECT SERVERPROPERTY('collation') ) | |
-- ALTER DATABASE AdventureWorks2008R2 COLLATE MODERN_SPANISH_CI_AS | |
BEGIN TRANSACTION | |
-- PASO 1: Migrar geografia | |
DECLARE @Colombia NVARCHAR(3) | |
DECLARE @LatinAmerica INT | |
DECLARE @Antioquia INT | |
-- Extraer el cod. de Colombia | |
SELECT @Colombia = CountryRegionCode | |
FROM | |
Person.CountryRegion | |
WHERE Name = 'Colombia' | |
--PRINT @Colombia | |
-- Agregar a Colombia como una zona de venta | |
INSERT INTO Sales.SalesTerritory | |
(CountryRegionCode, Name, [Group]) | |
VALUES | |
(@Colombia, 'Colombia', | |
'Latin America') | |
SET @LatinAmerica = SCOPE_IDENTITY() | |
-- Insertar el depto por defecto. | |
INSERT INTO Person.StateProvince | |
( Name, TerritoryID, CountryRegionCode, StateProvinceCode ) | |
VALUES | |
( | |
'Antioquia', @LatinAmerica, @Colombia, 'ANT' | |
) | |
SET @Antioquia = SCOPE_IDENTITY() | |
-- Pasar las direcciones | |
INSERT INTO Person.Address | |
(AddressLine1, City, StateProvinceID, PostalCode) | |
SELECT RTRIM(LTRIM(Direccion)), Contactos.dbo.Ciudad.Nombre, | |
@Antioquia, '574' | |
FROM Contactos.dbo.Contacto INNER JOIN Contactos.dbo.Ciudad | |
ON IdCiudad = Contactos.dbo.Ciudad.Id | |
WHERE Direccion + Contactos.dbo.Ciudad.Nombre | |
NOT IN ( | |
SELECT AddressLine1 + City FROM Person.Address | |
) | |
-- Pasar las personas | |
INSERT INTO Person.Contact | |
(FirstName, LastName, Phone, [PasswordHash], [PasswordSalt]) | |
SELECT Nombres, Apellidos, Telefono, HashBytes('SHA1', '123' + Nombres), '123' | |
FROM Contactos.dbo.Persona INNER JOIN Contactos.dbo.Contacto | |
ON IdContacto = Contactos.dbo.Contacto.Id | |
WHERE Nombres + Apellidos | |
NOT IN ( | |
SELECT FirstName + LastName FROM Person.Contact | |
) | |
SELECT * FROM Person.Contact WHERE FirstName + LastName IN ( | |
SELECT Nombres + Apellidos FROM Contactos.dbo.Persona | |
) | |
ROLLBACK TRANSACTION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment