SQL Server 2005 无法引用已“转换”的列
此查询有效:
select ist_id, ist_opis , CAST(ist_sifra as float ) as sifra
from IZOBRAZBENA_STOPNJA
where ist_aktivno<>0
order by sifra
但如果我只想仅在 sifra = 5 时查看,我会得到“无效的列名‘sifra’”。
select ist_id, ist_opis , CAST(ist_sifra as float ) as sifra
from IZOBRAZBENA_STOPNJA
where ist_aktivno<>0 and sifra = 5
order by sifra
我尝试将工作sql语句包装在另一个选择中,然后使用“where sifra = 5”它也失败了。
this query works:
select ist_id, ist_opis , CAST(ist_sifra as float ) as sifra
from IZOBRAZBENA_STOPNJA
where ist_aktivno<>0
order by sifra
but if I want to see only only when sifra = 5 I get "Invalid column name 'sifra'."
select ist_id, ist_opis , CAST(ist_sifra as float ) as sifra
from IZOBRAZBENA_STOPNJA
where ist_aktivno<>0 and sifra = 5
order by sifra
I tryed wraping working sql statement in another select and then using "where sifra = 5" it also fails..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这是事实。你应该做类似
ist_aktivno<>0 和 ist_sifra = 5 的事情
或
其中 ist_aktivno<>0 且 CAST(ist_sifra as float ) =5
yes, it is a fact. you sould do something like
where ist_aktivno<>0 and ist_sifra = 5
or
where ist_aktivno<>0 and CAST(ist_sifra as float ) =5
因为没有名为 sifra 的列。您也可以在 where 子句中进行强制转换
,或者引用未强制转换的列
Because there is no column named sifra. You either cast in the where clause as well
or refer the uncasted column