Hi everyone,
Iv been working on this access program which i have inherited from my predecessor. here is the query (inlcuding the do until loop etc) which i have found i need to modify to do wat i want;
Do Until select_part_rst.EOF
num = num + 1
SysCmd acSysCmdUpdateMeter, num
queryString2 = " INSERT INTO markup SELECT TOP 1 JDE_Customer_No AS [JDE Customer No], " & _
" Custom2.Customer_Name AS [Customer Name], part.id AS Part, price_list.price AS [Base Price], " & _
"price_factor.use_fixed_price AS [Factor2], price_factor.factor AS Factor, price_list.min_quantity AS [Price Break], part_select.quantity AS [Quantity Required], " & _
" part.unit_id As [Unit],(price_factor.factor*(price_list.price" & conversionRequired & ")) AS Price," & _
" part_select.BOM,part_select.BOMName,part_select.description As [BOM Description],part_select.[BOM Seq] As [BOM Seq], " & _
" part_select.RS1,part_select.RS2,part_select.RS3,part_select.info,part_select.Error, " & _
" part.lead_time As [Lead Time], " & ShipleyNorwalkStock & " As [Stock] " & _
" FROM part_select, part, price_list, price_factor, Custom2, CurrencyConUSD " & _
" WHERE part.id = part_select.part " & _
" AND price_list.part_id=part.id " & _
" AND Custom2.JDE_Price_Group=price_factor.customer_group " & _
" AND price_factor.part_group=part." & PriceGroup & _
" AND price_list.nationality= " & nationality & _
" AND Custom2.Customer_Name = " & "'" & CustomerSelection & "'" & _
" AND part.id = " & "'" & select_part_rst!part & "'" & _
" AND price_list.min_quantity <= part_select.quantity " & _
" AND part_select.quantity = " & select_part_rst!quantity & _
" AND part_select.BOM = " & "'" & select_part_rst!BOM & "'" & _
" AND part_select.[BOM Seq] = " & select_part_rst![BOM Seq] & _
" ORDER BY price_list.min_quantity DESC;"
select_part_rst.MoveNext
dbscurrent.Execute queryString2
Loop
What i need is for it to basically include a "if statement". Therefore, (I know this is completely incorrect but hopefully will get my point over), IF [Factor2] = '1' THEN price_factor.fixed_price_factor AS Factor ELSE price_factor.factor AS Factor. This IF statement would need to be ran repeatedly within the above SQL whenever the price_list or price_factor tables are used, thus to define whether to use e.g. price_list or fixed_price_list all depending on the figure within price_factor.use_fixed_price being a '1' or a '0'.
I have tried many different ways of doing this, and i am new to Access to struggling to get my head around it. Please could someone help!!! If there is no way to incorperate a IF statement in Access SQL, then how else could i do this? Thanks!!!
Iv been working on this access program which i have inherited from my predecessor. here is the query (inlcuding the do until loop etc) which i have found i need to modify to do wat i want;
Do Until select_part_rst.EOF
num = num + 1
SysCmd acSysCmdUpdateMeter, num
queryString2 = " INSERT INTO markup SELECT TOP 1 JDE_Customer_No AS [JDE Customer No], " & _
" Custom2.Customer_Name AS [Customer Name], part.id AS Part, price_list.price AS [Base Price], " & _
"price_factor.use_fixed_price AS [Factor2], price_factor.factor AS Factor, price_list.min_quantity AS [Price Break], part_select.quantity AS [Quantity Required], " & _
" part.unit_id As [Unit],(price_factor.factor*(price_list.price" & conversionRequired & ")) AS Price," & _
" part_select.BOM,part_select.BOMName,part_select.description As [BOM Description],part_select.[BOM Seq] As [BOM Seq], " & _
" part_select.RS1,part_select.RS2,part_select.RS3,part_select.info,part_select.Error, " & _
" part.lead_time As [Lead Time], " & ShipleyNorwalkStock & " As [Stock] " & _
" FROM part_select, part, price_list, price_factor, Custom2, CurrencyConUSD " & _
" WHERE part.id = part_select.part " & _
" AND price_list.part_id=part.id " & _
" AND Custom2.JDE_Price_Group=price_factor.customer_group " & _
" AND price_factor.part_group=part." & PriceGroup & _
" AND price_list.nationality= " & nationality & _
" AND Custom2.Customer_Name = " & "'" & CustomerSelection & "'" & _
" AND part.id = " & "'" & select_part_rst!part & "'" & _
" AND price_list.min_quantity <= part_select.quantity " & _
" AND part_select.quantity = " & select_part_rst!quantity & _
" AND part_select.BOM = " & "'" & select_part_rst!BOM & "'" & _
" AND part_select.[BOM Seq] = " & select_part_rst![BOM Seq] & _
" ORDER BY price_list.min_quantity DESC;"
select_part_rst.MoveNext
dbscurrent.Execute queryString2
Loop
What i need is for it to basically include a "if statement". Therefore, (I know this is completely incorrect but hopefully will get my point over), IF [Factor2] = '1' THEN price_factor.fixed_price_factor AS Factor ELSE price_factor.factor AS Factor. This IF statement would need to be ran repeatedly within the above SQL whenever the price_list or price_factor tables are used, thus to define whether to use e.g. price_list or fixed_price_list all depending on the figure within price_factor.use_fixed_price being a '1' or a '0'.
I have tried many different ways of doing this, and i am new to Access to struggling to get my head around it. Please could someone help!!! If there is no way to incorperate a IF statement in Access SQL, then how else could i do this? Thanks!!!