C# - SQL WITH 子句

发布于 2024-12-02 23:07:56 字数 597 浏览 0 评论 0原文

只是寻找想法 -

我有一个需要用 C# 解析的 SQL 语句。它的格式基本上如下 -

    WITH TableX as (

    -- something else could be here..
    select field1, field2, .. fieldX
    from mytable
    -- something else could be here..

    )

    -- something else could be here..
    select /*THESE FIELDS ARE BEING REPLACED*/ TableX.field1, TableX.field2, .. TableX.fieldX
    from TableX
    -- something else could be here.. ie, more joins, selecting from subqueries. Basically another select could exist here.

关于如何用保证在结果集中的另一组字段替换“TableX.field1,TableX.field2,.. TableX.fieldX”有什么想法吗?

Just fishing for ideas-

I have a SQL statement that I need to parse in C#. It is formatted basically as follows -

    WITH TableX as (

    -- something else could be here..
    select field1, field2, .. fieldX
    from mytable
    -- something else could be here..

    )

    -- something else could be here..
    select /*THESE FIELDS ARE BEING REPLACED*/ TableX.field1, TableX.field2, .. TableX.fieldX
    from TableX
    -- something else could be here.. ie, more joins, selecting from subqueries. Basically another select could exist here.

Any ideas on how to replace "TableX.field1, TableX.field2, .. TableX.fieldX" with another group of field guaranteed to be in the result set?

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

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

发布评论

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

评论(1

毁梦 2024-12-09 23:07:56

您可以使用完整的 sql 解析器来构建解析树,然后从那里有选择地替换项目。

这是一项不平凡的任务。

you could use a complete sql parser to build a parse tree, then replace the items selectively from there.

non-trivial task.

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