SQL Anywhere 条件 select 语句

SQL Anywhere Conditional select statement

我创建了这个程序,它获取数据库中的所有程序生成一个文档(通过注释)并列出所有 "in" 和 "out" 参数 - 这很好,它工作完美!

我面临的问题是,在我正在构建的应用程序中,我想 select 这些过程之一(因此当用户单击此列表中的一项时)并输出其详细信息(创建第二个过程来处理这个不是一个选项)

这是原始代码(忽略 p***** - 这是故意隐藏的(但从未在过程中使用 - 它用于记录)):

ALTER PROCEDURE "USER"."NetDefineProcs"
/* DOC
  Everything between the DOC tags are used to generate the user document.
*/
( in "p*****" char(20), in "pSearchTerm" long varchar, in "pSelectOne" char(1) default null) 
result( "proccessName" long varchar, "Doc" long varchar, "paramName" long varchar,"paramIO" long varchar,"paramDefault" long     varchar,"paramType" long varchar ) 
begin
    SELECT "proc_name" as "proccessName",
    (SELECT substr(source, charindex('/* DOC', source)+6, charindex('*/', source) - charindex('/* DOC', source)-6 ) FROM     "sys"."sysprocedure" where "proc_name" = "proccessName" AND charindex('/* DOC', source) > 0) as "Doc",
    "LIST"("parm_name" order by "parm_type" asc,"parm_id" asc) as "paramName",
    "LIST"("parm_type" order by "parm_type" asc,"parm_id" asc) as "paramIO",
    "LIST"("isnull"("default",'null') order by "parm_type" asc,"parm_id" asc) as "paramDefault",
    "LIST"("isnull"("domain_name",'null') order by "parm_type" asc,"parm_id" asc) as "paramType"
    from "sys"."sysprocedure" as "pr" key join "SYS"."SYSPROCPARM" as "pa" key join "SYS"."SYSDOMAIN"
  -- Below code requires sybase 16 - temporary version 11 friendly version above
  --  "LIST"("isnull"("base_type_str",'null') order by "parm_type" asc,"parm_id" asc) as "paramType"
  --  from "sys"."sysprocedure" as "pr" key join "SYS"."SYSPROCPARM" as "pa" --where pr.proc_name = o.proc_name  ;
  --  WHERE "proc_name" like 'net%' AND "proc_name" like '%' + pSearchTerm + '%'

    WHERE "proc_name" = pSearchTerm OR "proc_name" like 'net%' AND "proc_name" like '%' + pSearchTerm + '%'

    group by "proc_name"
    order by 1 asc
end

上面的代码可以很好地获取所有这些,现在这是我写的代码,试图只获取一个

ALTER PROCEDURE "USER"."NetDefineProcs"
/* DOC
  Everything between the DOC tags are used to generate the user document.
*/
( in "p*****" char(20), char(20), in "pSearchTerm" long varchar, in "pSelectOne" char(1) default null) 
result( "proccessName" long varchar, "Doc" long varchar, "paramName" long varchar,"paramIO" long varchar,"paramDefault" long varchar,"paramType" long varchar ) 
begin

    CASE
        WHEN pSelectOne = '1' THEN SELECT FIRST "proc_name" as "proccessName",
        ELSE SELECT "proc_name" as "proccessName",
    END

    (SELECT substr(source, charindex('/* DOC', source)+6, charindex('*/', source) - charindex('/* DOC', source)-6 ) FROM "sys"."sysprocedure" where "proc_name" = "proccessName" AND charindex('/* DOC', source) > 0) as "Doc",
    "LIST"("parm_name" order by "parm_type" asc,"parm_id" asc) as "paramName",
    "LIST"("parm_type" order by "parm_type" asc,"parm_id" asc) as "paramIO",
    "LIST"("isnull"("default",'null') order by "parm_type" asc,"parm_id" asc) as "paramDefault",
    "LIST"("isnull"("domain_name",'null') order by "parm_type" asc,"parm_id" asc) as "paramType"
    from "sys"."sysprocedure" as "pr" key join "SYS"."SYSPROCPARM" as "pa" key join "SYS"."SYSDOMAIN"
  -- Below code requires sybase 16 - temporary version 11 friendly version above
  --  "LIST"("isnull"("base_type_str",'null') order by "parm_type" asc,"parm_id" asc) as "paramType"
  --  from "sys"."sysprocedure" as "pr" key join "SYS"."SYSPROCPARM" as "pa" --where pr.proc_name = o.proc_name  ;
  --  WHERE "proc_name" like 'net%' AND "proc_name" like '%' + pSearchTerm + '%'

    WHERE "proc_name" = pSearchTerm OR "proc_name" like 'net%' AND "proc_name" like '%' + pSearchTerm + '%'

    group by "proc_name"
    order by 1 asc
end

现在我知道有一个语法错误,因为 select 语句有尾随的 ',' 但是有什么方法可以让我得到类似于我想要实现的东西而不需要它到达凌乱?

解决了!

将此添加到 "in" 参数

in "pSelectOne" char(1) default null

并将 where 子句更改为

WHERE (pSelectOne IS NOT NULL and "proc_name" = pSearchTerm) or (pSelectOne IS NULL and "proc_name" like 'net%' AND "proc_name" like '%' + pSearchTerm + '%')

而且有效。