Click here to Skip to main content
15,894,630 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I need to design a dynamic query / condition maker , for specifying discount on the items.
my problem is how can i specify logical operators between conditions???
Can any one suggest solution??

This for dynamically genrate conditions for applying discount on product price like if shape is abc and weight is grater than 1 kg then 0.1% discount.
Second is condition will be if shape is "def" or weight is less than 0.5 kg then discount is 0.6%
user can define this list dynamically

tnx
Posted
Updated 16-Jan-13 22:17pm
v2
Comments
Aarti Meswania 16-Jan-13 1:47am    
can you provide example input output table?
Hetal Jariwala 17-Jan-13 1:09am    
i know how to make single condition that is simple
but how can i allow user to specify the operators between conditions??
Aarti Meswania 17-Jan-13 1:34am    
information is not enough
if you will give a sample example like I have this data and want to filter like this then we can answer
so, please elaborate question
Hetal Jariwala 17-Jan-13 4:18am    
This for dynamically genrate conditions for applying discount on product price like if shape is abc and weight is grater than 1 kg then 0.1% discount.
Second is condition will be if shape is "def" or weight is less than 0.5 kg then discount is 0.6%
user can define this list dynamically
Could you please elaborate what exactly you need?

 
Share this answer
 
v2
Comments
Hetal Jariwala 16-Jan-13 0:42am    
Sorry but this links are not helpfull at all
Member 9626721 17-Jan-13 4:27am    
Use StringBuilder Class
This is ealiy done using Stored procedure

SQL
@shape varchar(50),
@wt decimal(18,2),

begin
 if(@shape = 'abc' and @wt>1)
   begin
       //your calulation   
   end
 if(@shape = 'gef' and @wt>0.5)
   begin
       //your calulation   
   end 

end 
 
Share this answer
 
Comments
Hetal Jariwala 18-Jan-13 0:50am    
bUT this conditions are defined by user not fixed
faisal23 18-Jan-13 1:49am    
ok its not fixed but it is stored in database and access from there or you have to make calculation at code
if user manages discount means you have data in table for weight like below...
discountSettings
StartRange EndRange ApplicableDisc
1          10       0.1%
10         100      0.2%


see example query...
SQL
with tbl_product as
(
    select 'p1' as product , 1  as wgt, 1000 as price
    union all
    select 'p2' as product , 15 as wgt, 1000 as price
)

select *,
    (price*ApplyDisc)/100 as DiscRs,price-((price*ApplyDisc)/100) as BillPrice
from tbl_product as a
    left join
    (
        --your discount setting table
        select 1  as StartRange, 10  as EndRange , 0.1 as ApplyDisc
            union all
        select 10 as StartRange, 100 as EndRange , 0.2 as ApplyDisc
    )
    as t on a.wgt between t.StartRange and t.EndRange --this is condition e.g. when weight is in range of 1 to 10 discount will 0.1 

Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900