1

I am wondering if it is possible to work out the best quote from multiple columns and then use the lowest value.

@quote1 = '1000.00'
@quote2 = '2000.00'
@quote3 = '3000.00'

so in the email i would like to select the @quote1 and all the quote information surrounding it IE quote, provider, etc

any help would be appricated!!!!!!!

1 Answer 1

0

There are numerous algorithms to find the lowest of three numbers. There are no arrays in AMPScript, so you basically have to do it manually.

%%[

var @quote1, @quote2, @quote3, @lowestQuote

set @quote1 = '3000.00'
set @quote2 = '1000.00'
set @quote3 = '2000.00'

set @lowestQuote = iif(@quote1 < iif(@quote2 < @quote3, @quote2, @quote3), @quote1, iif(@quote2 < @quote3, @quote2, @quote3))

]%%
<br>quote1: %%=v(@quote1)=%%
<br>quote2: %%=v(@quote2)=%%
<br>quote3: %%=v(@quote3)=%%
<br>lowestQuote: %%=v(@lowestQuote)=%%

Output

quote1: 3000.00 
quote2: 1000.00 
quote3: 2000.00 
lowestQuote: 1000.00 

You can also use SSJS. There's an example on how to do that here.

UPDATE 20150615

Utilizing the Add() function forces the strings to be evaluated as numbers:

%%[

var @quote1, @quote2, @quote3, @lowestQuote

set @quote1 = add('88.73',0)
set @quote2 = add('105.54',0)
set @quote3 = add('106.32',0)

set @lowestQuote = iif(@quote1 < iif(@quote2 < @quote3, @quote2, @quote3), @quote1, iif(@quote2 < @quote3, @quote2, @quote3))

]%%

<br>quote1: %%=v(@quote1)=%%
<br>quote2: %%=v(@quote2)=%%
<br>quote3: %%=v(@quote3)=%%
<br>lowestQuote: %%=v(@lowestQuote)=%%

Output

quote1: 88.73 
quote2: 105.54 
quote3: 106.32 
lowestQuote: 88.73
6
  • Hi Adam, thanks for this. could you explain the lowest quote as i am trying to understand the logic
    – Peter Ho
    Commented Jun 15, 2015 at 7:34
  • Hi Adam, just been testing this and its not pulling the cheapest quote<br>
    – Peter Ho
    Commented Jun 15, 2015 at 7:49
  • Hi Adam, just been testing this and its not pulling the cheapest quote it should pull quote1 - quote1: 88.73 quote2: 105.54 quote3: 106.32 lowestQuote: 105.54
    – Peter Ho
    Commented Jun 15, 2015 at 7:58
  • Are you using number or string values? Commented Jun 15, 2015 at 10:23
  • string value (text 50)
    – Peter Ho
    Commented Jun 15, 2015 at 11:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .