insert into select问题

jil420 2015-11-26 10:12:36
有张产品类别表productClass(id,name)
先在已知数据:比如12,23,34,45,产品类别1的id,产品类别2的id
想插入到产品表中,12,23,34,45,产品类别1的id,产品类别1的name,产品类别2的id,产品类别2的name
该如何插入呢?
多谢了
...全文
133 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jil420 2015-11-26
  • 打赏
  • 举报
回复
错误信息还是一样啊
LongRui888 2015-11-26
  • 打赏
  • 举报
回复
这个有问题: insert into SERV_ClinicJournal(JournalId,BillDepartCode,BillDepartName,DoDepartCode,DoDepartName) select('6a1d2529-c75e-498d-9795-63dc988de9ed', (select c.itemcode from serv_clinicitem c where c.itemname=SERV_ClinicJournal.BillDepartName),'妇科门诊', (select c.itemcode from serv_clinicitem c where c.itemname=SERV_ClinicJournal.DoDepartName),'妇科门诊') 这个试试: insert into SERV_ClinicJournal(JournalId,BillDepartCode,BillDepartName,DoDepartCode,DoDepartName) select('6a1d2529-c75e-498d-9795-63dc988de9ed', (select c.itemcode from serv_clinicitem c where c.itemname='妇科门诊'),'妇科门诊', (select c.itemcode from serv_clinicitem c where c.itemname='妇科门诊'),'妇科门诊')
jil420 2015-11-26
  • 打赏
  • 举报
回复
引用 3 楼 yupeigu 的回复:
试试这个: insert into product select 12,23,34,45, 产品类别1的id,(select name from productClass where id = 产品类别1的id), 产品类别2的id,(select name from productClass where id = 产品类别2的id)
我按照版主的样子写了个,可提示 消息 102,级别 15,状态 1,第 2 行 ',' 附近有语法错误。 消息 102,级别 15,状态 1,第 3 行 ',' 附近有语法错误。 消息 102,级别 15,状态 1,第 4 行 ',' 附近有语法错误。 看了半天,也没看出来错误

insert into SERV_ClinicJournal(JournalId,BillDepartCode,BillDepartName,DoDepartCode,DoDepartName)
 select('6a1d2529-c75e-498d-9795-63dc988de9ed',
(select c.itemcode from serv_clinicitem c where c.itemname=SERV_ClinicJournal.BillDepartName),'妇科门诊',
(select c.itemcode from serv_clinicitem c where c.itemname=SERV_ClinicJournal.DoDepartName),'妇科门诊')
LongRui888 2015-11-26
  • 打赏
  • 举报
回复
试试这个: insert into product select 12,23,34,45, 产品类别1的id,(select name from productClass where id = 产品类别1的id), 产品类别2的id,(select name from productClass where id = 产品类别2的id)
无涯大者 2015-11-26
  • 打赏
  • 举报
回复
同问 name 值是怎取的,如果是另外一个表查询得到的话 可以这样写 insert into productClass(id,name) select id,(select top 1 name from B where id=c.id) as name from c where xxxxx
Yole 2015-11-26
  • 打赏
  • 举报
回复
产品类别name哪里来的?
jil420 2015-11-26
  • 打赏
  • 举报
回复
正确为 insert into SERV_ClinicJournal(JournalId,BillDepartCode,BillDepartName,DoDepartCode,DoDepartName) select '6a1d2529-c75e-498d-9795-63dc988de9ed', (select c.itemcode from serv_clinicitem c where c.itemname='妇科门诊'),'妇科门诊', (select c.itemcode from serv_clinicitem c where c.itemname='妇科门诊'),'妇科门诊' 多谢了各位
jil420 2015-11-26
  • 打赏
  • 举报
回复
是什么原因啊,老是说 消息 102,级别 15,状态 1,第 2 行 ',' 附近有语法错误。 消息 102,级别 15,状态 1,第 3 行 ',' 附近有语法错误。 消息 102,级别 15,状态 1,第 4 行 ',' 附近有语法错误。 都是半角的标点啊,是其他的语法错误吗?

22,300

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧