Note that there are some explanatory texts on larger screens.

plurals
  1. POTSQL: Select with dynamic WHERE come from another table
    primarykey
    data
    text
    <p>I am developing a solution for statistic data for a customer and now i need to select some rows <code>from a table</code> (<strong>sell data</strong>) by using dynamic condition that come from <strong>another table</strong> (filled by the customer and it can change daily).</p> <p>Also i need to use a cursor to perform more calculation and other stuff so this is the scenario:</p> <pre><code>DECLARE cRiga CURSOR LOCAL FAST_FORWARD FOR -- here i will put the SELECT ... OPEN cRiga FETCH NEXT FROM cRiga INTO @field1, @field2, @field3, ... WHILE @@FETCH_STATUS = 0 BEGIN -- do some stuff here ... FETCH NEXT FROM cRiga INTO @field1, @field2, @field3, ... END CLOSE cRiga DEALLOCATE cRiga </code></pre> <p>this is the <strong>Condition Table</strong> where i can find the dynamic condition (see the colum Completa = 0)</p> <pre><code>IDIncentive CdMarca CdSettore CdGruppo Completa ----------- ------- --------- -------- ----------- 1 COES NULL NULL 1 1 DELONG 10 0024 0 &lt; 1 RHOSS NULL NULL 1 1 SILE 10 0012 0 &lt; 1 SILE 11 0025 0 &lt; 1 THERMI NULL NULL 1 ....... more rows ... </code></pre> <p>To be more clear i try to explode the SQL required in many queries as:</p> <pre><code>Select Field1, ... from SELLDATA where IDIncentive=1 and CdMarca='DELONG' and CdSettore=10 and CdGruppo='0024' UNION ALL Select Field1, ... from SELLDATA where IDIncentive=1 and CdMarca='SILE' and CdSettore=10 and CdGruppo='0012' UNION ALL Select Field1, ... from SELLDATA where IDIncentive=1 and CdMarca='SILE' and CdSettore=11 and CdGruppo='0025' </code></pre> <p>As u can imagine i cant do that because the conditions change daily by the customer so my question is:</p> <p><strong>How i can create a select that have all the conditions (as my example above) to use in the cursor ? There are a way ?</strong></p> <p>Thanks for who can help me and please advise if need more information to make more clear this question</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload