CREATE TABLE Table1
(
Column1 INT IDENTITY(1,1) PRIMARY KEY,
Column2 VARCHAR(20) NOT NULL,
Column3 VARCHAR(50) NOT NULL,
Column4 VARCHAR(50) NOT NULL
)
INSERT INTO Table1 VALUES('Mr','AAA','111')
INSERT INTO Table1 VALUES('Mrs','BBB','222')
INSERT INTO Table1 VALUES('Miss','CCC','333')
INSERT INTO Table1 VALUES('Mr','DDD','444')
INSERT INTO Table1 VALUES('Mrs','EEE','555')
CREATE TABLE Table2
(
Col1 INT IDENTITY(1,1) PRIMARY KEY,
Col2 VARCHAR(20) NOT NULL,
Col3 VARCHAR(50) NOT NULL,
Col4 VARCHAR(50) NOT NULL
)
INSERT INTO Table2 VALUES('','','')
INSERT INTO Table2 VALUES('','','')
INSERT INTO Table2 VALUES('','','')
INSERT INTO Table2 VALUES('','','')
DECLARE @Column1 INT
DECLARE @Column2 VARCHAR(20)
DECLARE @Column3 VARCHAR(50)
DECLARE @Column4 VARCHAR(50)
SELECT TOP 1
@Column1 = Column1 ,
@Column2 = Column2 ,
@Column3 = Column3 ,
@Column4 = Column4
FROM
Table1
ORDER BY NEWID()
UPDATE Table2
SET
Col2 = @Column2 ,
Col3 = @Column3 ,
Col4 = @Column4
FROM
Table2 T1
INNER JOIN
(
SELECT TOP 1 Col1 FROM Table2 ORDER BY NEWID()
) T2 ON T2.Col1 = T1.Col1
No comments:
Post a Comment