0

SQLServer2008クエリで動的入力値を処理する方法。

私のシナリオは以下のクエリにあります。2つの入力パラメータがJavaからi-batisを通過します。

 1) if i enter stlmtTransId field alone query should execute (paymentTransId  is empty now).
 2) if i enter paymentTransId field alone query should execute(stlmtTransId  is empty now).
 3) if i enter both input values query should execute for matching the two inputs.

上記のいずれの場合でも、出力が必要です。それを処理する方法。

  SELECT
    STLMT_TRANS.SETTLEMENT_TRANSACTION_ID
    ,STLMT_TRANS.PC_TRANSACTION_ID
    ,STLMT_TRANS.TRANSACTION_AMOUNT
    ,STLMT_TRANS.PAYMENT_AGENT_ID
    ,STLMT_TRANS.PAYMENT_AGENCY_ID
    ,STLMT_TRANS.PAYMENT_TRANS_DATE
    FROM
    T_SETTLEMENT_TRANSACTION STLMT_TRANS WITH (NOLOCK)
    WHERE
    STLMT_TRANS.SETTLEMENT_TRANSACTION_ID=#stlmtTransId#
    AND
    STLMT_TRANS.PC_TRANSACTION_ID=#paymentTransId#

注:Java+I-Batisを使用しているim

4

2 に答える 2

0
WHERE
(
 (STLMT_TRANS.SETTLEMENT_TRANSACTION_ID=#stlmtTransId#) or (#stlmtTransId# is NULL)
)
AND
(
  (STLMT_TRANS.PC_TRANSACTION_ID=#paymentTransId#) or (#paymentTransId# is NULL)
)
于 2013-01-09T13:48:16.473 に答える
0
SELECT
STLMT_TRANS.SETTLEMENT_TRANSACTION_ID
,STLMT_TRANS.PC_TRANSACTION_ID
,STLMT_TRANS.TRANSACTION_AMOUNT
,STLMT_TRANS.PAYMENT_AGENT_ID
,STLMT_TRANS.PAYMENT_AGENCY_ID
,STLMT_TRANS.PAYMENT_TRANS_DATE
FROM
T_SETTLEMENT_TRANSACTION STLMT_TRANS WITH (NOLOCK)
WHERE STLMT_TRANS.SETTLEMENT_TRANSACTION_ID = ISNULL(@stlmtTransId, STLMT_TRANS.SETTLEMENT_TRANSACTION_ID)
AND STLMT_TRANS.PC_TRANSACTION_ID = ISNULL(@paymentTransId, STLMT_TRANS.PC_TRANSACTION_ID)
于 2013-01-09T14:02:41.413 に答える