考试成绩统计问题:
如果成绩表(c2cj)中存在化学科(HX)成绩,则计算平均分,否则@temhxpj为0分,但是用下面语句总中提示
“服务器: 消息 207,级别 16,状态 3,行 14
列名 'hx' 无效。”DECLARE @temhxpj decimal(4,1)
if exists(select 1 from syscolumns where id=object_id('c2cj') and name='hx')
select @temhxpj=round(avg(hx),2) from mydata.dbo.c2cj
select @temhxpj=0问题出在哪里?
如果成绩表(c2cj)中存在化学科(HX)成绩,则计算平均分,否则@temhxpj为0分,但是用下面语句总中提示
“服务器: 消息 207,级别 16,状态 3,行 14
列名 'hx' 无效。”DECLARE @temhxpj decimal(4,1)
if exists(select 1 from syscolumns where id=object_id('c2cj') and name='hx')
select @temhxpj=round(avg(hx),2) from mydata.dbo.c2cj
select @temhxpj=0问题出在哪里?
if exists(select 1 from mydata..syscolumns where id=object_id('c2cj') and name='hx')
select @temhxpj=round(avg(hx),2) from mydata.dbo.c2cj
考试成绩统计问题:
如果成绩表(c2cj)中存在化学(HX)字段,则计算平均分(用变量@temhxpj表示),如果不存在化学字段,则@temhxpj=0,但是用下面语句总中提示
“服务器: 消息 207,级别 16,状态 3,行 14
列名 'hx' 无效。” DECLARE @temhxpj decimal(4,1) /*定义变量*/
if exists(select 1 from syscolumns where id=object_id('c2cj') and name='hx') /*判断字段是否存在*/
select @temhxpj=round(avg(hx),2) from mydata.dbo.c2cj
else
select @temhxpj=0 问题出在哪里?
object_id('c2cj')--这是在mydata数据库下面执行的吗