Imam Tabela0 [ID],[Ime],[Prezime]
Tablea1 koja ima [Tabela0ID], [RoleID]
Relacija je jedan prema mnogo (za Jedno ime i prezime moze da ima mnogo Role)
Trebam da migriram u tabelu Tabela2 [ID],[Ime],[Prezime],[RoleID]
Problem je sto u novu tabelu imam samo jedno polje a u staru tabelu za jedan zapisi imam i po 10 zapisa. Fali mi logika kako da izvedem kad dobijem vise od jedan zapis i ako taj zapis je recimo u IN(10,22,34,78) na mesto sve to zapisi 1...koristio sam WHEN ali tad trebam da upisem tacan uslov sto znaci da ne pomaze. Ikakva ideja ili pomoc...evo deo koda. Hvala
Code:
DECLARE @EntityRepresentationID TABLE(
ID int,
OldID int);
INSERT INTO @EntityRepresentation
SELECT ua.usr_user_pk, ua.usr_description,
(SELECT TOP 1 ID FROM @EntityID WHERE OldID = ua.usr_pty_user_party_fk),
(SELECT TOP 1 ID FROM @EntityID WHERE OldID = ua.usr_pty_represented_party_fk),
ua.usr_status, ua.usr_create_timestamp, ua.usr_last_update_timestamp, ua.usr_read_terms, ua.usr_read_timestamp,
CASE WHEN ur.[usl_rle_role_fk] IN (103, 102, 53) THEN 1 WHEN ur.[usl_rle_role_fk] = 49 THEN 2 WHEN ur.[usl_rle_role_fk] = 50 THEN 3 ELSE NULL END
FROM [SRV_STANDARDDB].EAPPS.dbo.tb_user_account ua
LEFT OUTER JOIN [SRV_STANDARDDB].EAPPS.dbo.tb_user_role ur ON (ua.usr_user_pk = ur.[usl_usr_user_fk] AND ur.[usl_rle_role_fk] IN (103, 102, 53, 49, 50))
WHERE usr_pty_user_party_fk != 0
DECLARE @EntityRepresentationID TABLE(
ID int,
OldID int);
INSERT INTO @EntityRepresentation
SELECT ua.usr_user_pk, ua.usr_description,
(SELECT TOP 1 ID FROM @EntityID WHERE OldID = ua.usr_pty_user_party_fk),
(SELECT TOP 1 ID FROM @EntityID WHERE OldID = ua.usr_pty_represented_party_fk),
ua.usr_status, ua.usr_create_timestamp, ua.usr_last_update_timestamp, ua.usr_read_terms, ua.usr_read_timestamp,
CASE WHEN ur.[usl_rle_role_fk] IN (103, 102, 53) THEN 1 WHEN ur.[usl_rle_role_fk] = 49 THEN 2 WHEN ur.[usl_rle_role_fk] = 50 THEN 3 ELSE NULL END
FROM [SRV_STANDARDDB].EAPPS.dbo.tb_user_account ua
LEFT OUTER JOIN [SRV_STANDARDDB].EAPPS.dbo.tb_user_role ur ON (ua.usr_user_pk = ur.[usl_usr_user_fk] AND ur.[usl_rle_role_fk] IN (103, 102, 53, 49, 50))
WHERE usr_pty_user_party_fk != 0
Kude tumbe i tri bandere