如果 SQL 表达式具有带有 SUBSELECT 查询的 LENGTH 函数,则将其转换为 SQLite

发布于 2024-12-06 01:52:26 字数 824 浏览 1 评论 0原文

我知道在 SQLite 中,我们使用 LENGTH 函数而不是 len。但是,当我想将 LENGTH 函数与子查询一起使用时,如下所示:

select length(select name from tblNames where name=1)

我收到错误。这是表达式的 Microsoft SQL 版本:

iif(len((select  BilgiAcik  from DigerBilg  where BilgTip=12  and BilgDgr=Cstr(Dr.Fr)))>0,( select  BilgiAcik  from DigerBilg  where BilgTip=12 and BilgDgr=Cstr(Dr.Fr)),Cstr(Dr.Fr))  as Fr,

我将上面的表达式转换为 SQLite,如下所示:

(case length((select  BilgiAcik  from DigerBilg where BilgTip=12 and BilgDgr=CAST(Dr.Fr as TEXT))>0 ( select  BilgiAcik  from DigerBilg  where BilgTip=12 and BilgDgr=Cstr(Dr.Fr)) else CAST(Dr.Fr as TEXT) end) as Fr,

我做错了什么?我不能仅将 SUBSELECT 查询与 LRNGTH 函数一起使用吗?关于如何解决这个问题有什么建议吗?

I know that in SQLite, we use the LENGTH function instead of len. But when I want to use the LENGTH function with a subquery like so:

select length(select name from tblNames where name=1)

I receive an error. Here is the Microsoft SQL version of the expression:

iif(len((select  BilgiAcik  from DigerBilg  where BilgTip=12  and BilgDgr=Cstr(Dr.Fr)))>0,( select  BilgiAcik  from DigerBilg  where BilgTip=12 and BilgDgr=Cstr(Dr.Fr)),Cstr(Dr.Fr))  as Fr,

I converted the above expression into SQLite as so:

(case length((select  BilgiAcik  from DigerBilg where BilgTip=12 and BilgDgr=CAST(Dr.Fr as TEXT))>0 ( select  BilgiAcik  from DigerBilg  where BilgTip=12 and BilgDgr=Cstr(Dr.Fr)) else CAST(Dr.Fr as TEXT) end) as Fr,

What I'm I doing wrong about? Can't I just use the SUBSELECT query with the LRNGTH function? Any suggestions on how to solve this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

被你宠の有点坏 2024-12-13 01:52:26

您将需要重组您的声明,使其更类似于以下内容。

select length(name) from (select name from tblnames where name=1);

如果您愿意,您可以通过为子选择添加别名来更轻松地管理它。

select length(t.name) from (select name from tblnames where name=1) as t;

You will want to restructure your statement to be more similar to the following.

select length(name) from (select name from tblnames where name=1);

You can manage this a bit more easily by aliasing the subselects if you like.

select length(t.name) from (select name from tblnames where name=1) as t;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文