--select * from SmallLists where Type =1
--select * from SmallLists where Type =101 and title like N'%متر%'
--update SmallLists set description = null where Type =1 

DECLARE @ID as bigint
DECLARE @Type as Int
DECLARE @Title as NVarChar(100)
DECLARE @N as int
DECLARE @Code as NVarChar(100)

DECLARE myCursor CURSOR FOR 
select ID, Type, Title  from SmallLists where Type=1

--#*#*1627*#16*##*1627*#'
OPEN myCursor
FETCH NEXT FROM myCursor INTO @ID, @Type, @Title
WHILE @@FETCH_STATUS = 0
BEGIN
	Select @N=COUNT(ID) from SmallLists where Type=101 and Title=@Title 
	print @N
	if @N = 1 
	BEGIN
		Select @Code=Left(Description,10) from SmallLists where Type=101 and Title=@Title 
		UPDATE SmallLists set Description = N'#*'+@Code+N'*#'+coalesce(Description,'') 
			where Type=1 and Title=@Title and (Description is null or Len(Description)<2 or Left(Description,2) <> N'#*')
	END

	FETCH NEXT FROM myCursor INTO @ID, @Type, @Title
END

CLOSE myCursor
DEALLOCATE myCursor

