SQL Server 2005 无法引用已“转换”的列

发布于 2024-11-08 03:30:10 字数 450 浏览 0 评论 0原文

此查询有效:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱花落人离去 2024-11-15 03:30:10

是的,这是事实。你应该做类似

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

极致的悲 2024-11-15 03:30:10

因为没有名为 sifra 的列。您也可以在 where 子句中进行强制转换

select ist_id,  ist_opis , CAST(ist_sifra as float ) as sifra 
from IZOBRAZBENA_STOPNJA 
where ist_aktivno<>0 and CAST(ist_sifra as float ) = 5
order by sifra

,或者引用未强制转换的列

select ist_id,  ist_opis , CAST(ist_sifra as float ) as sifra 
from IZOBRAZBENA_STOPNJA 
where ist_aktivno<>0 and ist_sifra = 5
order by sifra

Because there is no column named sifra. You either cast in the where clause as well

select ist_id,  ist_opis , CAST(ist_sifra as float ) as sifra 
from IZOBRAZBENA_STOPNJA 
where ist_aktivno<>0 and CAST(ist_sifra as float ) = 5
order by sifra

or refer the uncasted column

select ist_id,  ist_opis , CAST(ist_sifra as float ) as sifra 
from IZOBRAZBENA_STOPNJA 
where ist_aktivno<>0 and ist_sifra = 5
order by sifra
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文