On Microsoft SQL Server 2008, I have a table with Products:
Id | Name | DefaultImageId
And one with Images:
Id | ProductId |
declare @carg_id as int
DECLARE cursor_cargo CURSOR FOR
SELECT carg_id FROM cargo
OPEN cursor_cargo
FETCH NEXT FROM cursor_cargo
INTO @carg_id
WHILE @@FETCH_STATUS =0
BEGIN
update cargo set ciud_id = (
select top 1 ciud_id from ciudad
inner join Pais on Pais.pais_id = ciudad.pais_id
where ciudad.pais_id is not null and empr_id is null and pais_status =1 order by NEWID()) WHERE CARG_ID = @CARG_ID
FETCH NEXT FROM cursor_cargo
INTO @carg_id
END
CLOSE cursor_cargo
DEALLOCATE cursor_cargo