我正在使用Mule4和AnyPoint7,并希望设置数据库连接器以从我的SQL server数据库表中选择所有客户,但是如果在请求中填充了customerName查询参数,那么我希望添加WHERE子句,以便只返回与customerName查询参数同名的客户,否则它应该只返回所有客户。
我的代码如下,但我正在努力使语法正确。
<db:select doc:name="Select Customers" doc:id="98a4aa2f-b0b6-4fb5-ab27-d70489fd532d" config-ref="db-config">
<ee:repeatable-file-store-iterable />
<db:sql >SELECT TOP 10 * FROM MYDB.dbo.Customer $(if (attributes.queryParams.customerName != null and isEmpty(attributes.queryParams.customerName) == false) "WHERE Name = :customerName" else "")</db:sql>
<db:input-parameters ><![CDATA[#[{'customerName' : attributes.queryParams.customerName}]]]></db:input-parameters>
</db:select>我该怎么做呢?
谢谢
https://stackoverflow.com/questions/51398528
复制相似问题