把某张表的某一列数据随机放到另一张表的某一列sql语句
这是我解决方案,用个存储过程解决的
ALTER PROCEDURE [dbo].[dd]
AS
BEGIN
DECLARE @Count int ,
@F INT
DECLARE authors_cursor CURSOR FOR
select CompanyId from Company.Companies
OPEN authors_cursor
FETCH NEXT FROM authors_cursor INTO @F
WHILE @@FETCH_STATUS = 0
BEGIN
update table SET updateColumn=(select top 1 CityId from Cities order by newid()) where tianjia
print '@F='+cast(@F as NVARCHAR(10))
FETCH NEXT FROM authors_cursor INTO @F
END
CLOSE authors_cursor
DEALLOCATE authors_cursor
END
GO
自己解决方案:DECLARE @F INT
DECLARE authors_cursor CURSOR FOR
select colomn from Table
OPEN authors_cursor
FETCH NEXT FROM authors_cursor INTO @F
WHILE @@FETCH_STATUS = 0
BEGIN
update table SET Company.Companies.CityId=(select top 1 colomn from Cities where条件 order by newid()) where CompanyId=@F
print '@F='+cast(@F as NVARCHAR(10))
FETCH NEXT FROM authors_cursor INTO @F
END
CLOSE authors_cursor
DEALLOCATE authors_cursor