SQL 帮助 |INSERT 语句的选择列表包含的项目少于插入列表 [英] SQL Help | The select list for the INSERT statement contains fewer items than the insert list

查看:97
本文介绍了SQL 帮助 |INSERT 语句的选择列表包含的项目少于插入列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请看下面我的查询,

insert into dbo.orderDetails(orderNo,clientId,productId,quantity)
values(' ee941422-5546-4d62-b5d6-60ecd13ca2b8 ')
select client_id,product_id,amount from dbo.cart
where client_id =' efc08f7c-fdfc-4712-9488-fc1c55acb95e ' ;

在这个我想要一个静态的orderno,其余的应该来自​​一个表(dbo.cart).当我执行我的查询时它会显示这个错误

In this I want a static orderno and the rest should come from the a table(dbo.cart).when i execute my query its shows this error

There are more columns in the INSERT statement than values specified in the 
VALUES clause. The number of values in the VALUES clause must match the 
number of columns specified in the INSERT statement.

任何解决方案.

推荐答案

VALUESSELECT 不能同时存在.如果要插入静态值,请将其放入 SELECT 列表中.

You can't have both VALUES and SELECT. If you want to insert static values, put it into the SELECT list.

insert into dbo.orderDetails(orderNo,clientId,productId,quantity)
select ' ee941422-5546-4d62-b5d6-60ecd13ca2b8 ', client_id,product_id,amount from dbo.cart
where client_id =' efc08f7c-fdfc-4712-9488-fc1c55acb95e ' ;

这篇关于SQL 帮助 |INSERT 语句的选择列表包含的项目少于插入列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆