| re: How to use where wiht variable
Hmmm... I will explane the problem with "psevdo" code (sorry for my Englesh)...
I have sales data in table KUM_SALES (like cumulative_sales). Condition is written in table SALES_COND.
Kum_sales have fields like:
- YEAR
- CUSTOMER_ID
- QUANTITY
- VALUES_ WITHOUT_VAT
- VAT
- VALUES_WITH_VAT
Table SALES_COND have fields:
- TYPE_COND (tipe of condition)
- COND (description of condition)
for exemple, my customer will choice:
TYPE_COND = 1 OR 2 OR 3, ...
IN TYPE OF CONDITION IS WRITEN:
1 = YEAR = 2009 AND CUSTOMER_ID IN ('123','223','333')
2 = YEAR = 2008 AND CUSTOMER_ID IS NOT IN ('123','223','333')
3 = CUSTOMER_ID LIKE '5%'
...
the main quiry is the same for every type of condition:
SELECT YEAR,
CUSTOMER_ID,
SUM(QUANTITY) AS QUIANTITY,
SUM(VAT) AS VAT,
...
FROM KUM_SALES
WHERE ...
-- here need to be (select from a cond_table where type_cond = for example 3)
CUSTOMER_ID LIKE '5%'
I think it cann be solved with SP_EXCECUTEQUIRY, where i cann build quiry... But whenn is posible to geth a simples example, it will be very usefull
Tnx,
Darko
|