sql语法,急用

qianniao08 2008-11-29 01:30:00
insert into mark(stuid,courseid) values('20080001',courseid=(select courseid from course where coursename='数据结构')
错误了,应该怎么做
我不想设置变量,不想用存储过程
...全文
108 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
qianniao08 2008-11-29
  • 打赏
  • 举报
回复
3q
chekx 2008-11-29
  • 打赏
  • 举报
回复
这样就可以了??试试??
WinnLei 2008-11-29
  • 打赏
  • 举报
回复
insert into mark(stuid,courseid)
values('20080001',select top 1 courseid from course where coursename='数据结构'))
即可
特别 2008-11-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 qinhl99 的回复:]
引用楼主 qianniao08 的帖子:
insert into mark(stuid,courseid) values('20080001',courseid=(select courseid from course where coursename='数据结构')
错误了,应该怎么做
我不想设置变量,不想用存储过程


//
insert into mark(stuid,courseid)
select '20080001', courseid
from course where coursename='数据结构'

[/Quote]
为防止出现多条coursename='数据结构'的数据,可进一步改为
insert into mark(stuid,courseid)
select top 1 '20080001', courseid
from course where coursename='数据结构'
Wesley 2008-11-29
  • 打赏
  • 举报
回复
帮顶~
patrickpan 2008-11-29
  • 打赏
  • 举报
回复
insert into mark(stuid,courseid) values('20080001',courseid=(select courseid from course where coursename='数据结构')
改为:
insert into mark(stuid,courseid) select '20080001',courseid from course where coursename='数据结构'
wuyq11 2008-11-29
  • 打赏
  • 举报
回复
insert into mark(stuid,courseid) select '20080001',courseid from course where coursename='数据结构'
vbman2003 2008-11-29
  • 打赏
  • 举报
回复
insert into mark(stuid,courseid) select '20080001',courseid from course where coursename='数据结构'
winsei 2008-11-29
  • 打赏
  • 举报
回复
不想设置变量呀~~~~汗
winsei 2008-11-29
  • 打赏
  • 举报
回复
DECLARE @courseid nvarchar(15)--变量类型自行定义
set @courseid=(select courseid from course where coursename='数据结构')
insert into mark(stuid,courseid) values('20080001', @courseid)
qinhl99 2008-11-29
  • 打赏
  • 举报
回复
[Quote=引用楼主 qianniao08 的帖子:]
insert into mark(stuid,courseid) values('20080001',courseid=(select courseid from course where coursename='数据结构')
错误了,应该怎么做
我不想设置变量,不想用存储过程
[/Quote]

//
insert into mark(stuid,courseid)
select '20080001', courseid
from course where coursename='数据结构'
zjs1109 2008-11-29
  • 打赏
  • 举报
回复
不允许使用列名..不会,帮顶,别沉了,关注
阿建像熊猫 2008-11-29
  • 打赏
  • 举报
回复
没错吧。

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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