首页 新闻 会员 周边

把某张表的某一列数据随机放到另一张表的某一列sql语句急急急急急急急急急急急急急急急急急急急急

0
[已解决问题] 解决于 2012-04-09 15:48

把某张表的某一列数据随机放到另一张表的某一列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

sql
MingHao_Hu的主页 MingHao_Hu | 初学一级 | 园豆:8
提问于:2012-04-09 15:16
< >
分享
最佳答案
0

自己解决方案: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

奖励园豆:5
MingHao_Hu | 初学一级 |园豆:8 | 2012-04-09 15:47
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册