Sql server Sql插入命令歧义
我试着使用像这样的sql命令,但是由于一些明显的原因它不起作用。你能告诉我这种命令的解决方法吗Sql server Sql插入命令歧义,sql-server,insert,select-insert,Sql Server,Insert,Select Insert,我试着使用像这样的sql命令,但是由于一些明显的原因它不起作用。你能告诉我这种命令的解决方法吗 INSERT INTO ContentToGroup(ContentId,ClassSectionId) VALUES (16, Select ClassSectionId from ClassSectionMaster where ClassId=1) 您不能混合使用INSERT。。。。值…带有“内联”select语句。使用VALUES关键字,必须将所有值作为文本或SQL变量提供
INSERT INTO ContentToGroup(ContentId,ClassSectionId)
VALUES (16, Select ClassSectionId from ClassSectionMaster where ClassId=1)
您不能混合使用
INSERT。。。。值…
带有“内联”select语句。使用VALUES
关键字,必须将所有值作为文本或SQL变量提供
您需要首先选择值并将其分配给变量:
DECLARE @ClassSectionID INT
SELECT @ClassSectionID = ClassSectionID
FROM dbo.ClassSectionMaster WHERE ClassId = 1
INSERT INTO ContentToGroup(ContentId,ClassSectionId)
VALUES (16, @ClassSectionID)
或者使用其他人显示的
SELECT
语句提供所有值(然后省略values
关键字)使用嵌套查询时,首先需要删除值。还可以尝试在字段名前面指定表名,以防引起歧义
INSERT INTO ContentToGroup(ContentId,ClassSectionId)
SELECT 16, ClassSectionMaster.ClassSectionId
FROM ClassSectionMaster
WHERE ClassSectionMaster.ClassId=1
我认为应该在某处显示“x人正在回答”。因为我们都发布了几乎相同的答案
INSERT INTO ContentToGroup(ContentId,ClassSectionId) Select 16, ClassSectionId from ClassSectionMaster where ClassId=1
INSERT INTO ContentToGroup(ContentId,ClassSectionId)
SELECT 16, ClassSectionMaster.ClassSectionId
FROM ClassSectionMaster
WHERE ClassSectionMaster.ClassId=1