Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将数据从MS SQL表中的2列复制到另一个表中的1列_Sql_Sql Server - Fatal编程技术网

将数据从MS SQL表中的2列复制到另一个表中的1列

将数据从MS SQL表中的2列复制到另一个表中的1列,sql,sql-server,Sql,Sql Server,我试图将tblFixtures中存储的比赛获胜者复制到tblEntrants中的单个列中。所以我基本上希望在tblEntrants中的AccountID列中创建一个获奖者列表,如下所示 tblFixtures Columns: Player1 resultPLayer1 Player2 ResultPlayer2, CompID john 5 stu 2 (Guid)

我试图将tblFixtures中存储的比赛获胜者复制到tblEntrants中的单个列中。所以我基本上希望在tblEntrants中的AccountID列中创建一个获奖者列表,如下所示

tblFixtures Columns: Player1 resultPLayer1 Player2 ResultPlayer2, CompID
                       john        5         stu         2        (Guid) 
                       dave        0         max         5        (Guid)

tblEntrants Columns: AccountID, CompID
                        john    (Guid)
                        dave    (Guid)
这是我到目前为止试过的,但不起作用

INSERT INTO tblEntrants(AccountID,compID) SELECT(CASE WHEN (SELECT resultplayer1 FROM tblfixtures) > (SELECT resultplayer2 FROM tblfixtures) THEN (SELECT player1 FROM tblfixtures) END), @compID

INSERT INTO tblEntrants(AccountID,compID) SELECT(CASE WHEN (SELECT resultplayer2 FROM tblfixtures) > (SELECT resultplayer2 FROM tblfixtures) THEN (SELECT player2 FROM tblfixtures) END), @compID
你可以用这个

INSERT INTO tblEntrants(AccountID,compID) 
SELECT CASE WHEN ResultPlayer2 > resultPLayer1 THEN Player2 ELSE Player1 END, CompID
FROM tblfixtures
试试这个:您可以使用带有大小写的单个SELECT语句


非常感谢。我知道这很简单,但我还在这里学习。效果很好。
INSERT INTO tblEntrants(AccountID,compID)
SELECT
    CASE WHEN resultPLayer1 > ResultPlayer2 THEN player1 ELSE player2 END, @compID
FROM tblFixtures