从C#中的SQL查询获取子字符串

发布于 2025-01-20 18:40:51 字数 329 浏览 1 评论 0原文

我需要从其中包含某个单词的查询中获取一个子字符串(例如,单词是@param,后跟一个数字),例如:

SELECT *
FROM table t
WHERE t.column1 = @param1
AND t.column2 = @param2

我需要的是从查询中提取以下行

WHERE t.column1 = @param1

,而

AND t.column2 = @param2

SQL代码在内部定义IBM Cognos报告。

有建议吗?

I need to get a substring from a query that has a certain word inside it (the word is @param followed by a number), for example:

SELECT *
FROM table t
WHERE t.column1 = @param1
AND t.column2 = @param2

What I need is to extract the following lines from the query

WHERE t.column1 = @param1

And

AND t.column2 = @param2

The SQL code is defined inside IBM Cognos reports.

Any suggestion?

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

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

发布评论

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

评论(1

花开浅夏 2025-01-27 18:40:51

请检查此程序

public static void Main()
    {
        string query = @"SELECT *
                        FROM table t
                        WHERE t.column1 = @param1
                        AND t.column2 = @param2";

        string[] queries = query.Split("\n");
        bool isConditionStarted = false;
        foreach (string q in queries)
        {
            if (isConditionStarted)
                Console.WriteLine(q.Trim());
            else if (q.Trim().ToLower().Contains("where"))
            {
                isConditionStarted = true;
                Console.WriteLine(q.Trim());
            }
        }

    }

Please check this program

public static void Main()
    {
        string query = @"SELECT *
                        FROM table t
                        WHERE t.column1 = @param1
                        AND t.column2 = @param2";

        string[] queries = query.Split("\n");
        bool isConditionStarted = false;
        foreach (string q in queries)
        {
            if (isConditionStarted)
                Console.WriteLine(q.Trim());
            else if (q.Trim().ToLower().Contains("where"))
            {
                isConditionStarted = true;
                Console.WriteLine(q.Trim());
            }
        }

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