Your "mergefields" or personalization strings can only be referenced with the double-percent notation if they are columns in your sending Data Extension or are Profile Attributes. Any value retrieved outside of those two things needs to be referenced using the v() AMPScript function. For example:
%%[
var @rows, @row, @rowCount, @numRowsToReturn, @lookupValue, @i
set @lookupValue = "whee"
set @numRowsToReturn = 0 /* 0 means all */
set @rows = LookupOrderedRows("DataExtensionName",@numRowsToReturn,"DEColumn1 desc, DEColumn2 asc","LookupColumn", @lookupValue)
set @rowCount = rowcount(@rows)
if @rowCount > 0 then
for @i = 1 to @rowCount do
var @DEColumn1, @DEColumn2
set @row = row(@rows,@i) /*get row based on loop counter */
set @DEColumn1 = field(@row,"DEColumn1")
set @DEColumn2 = field(@row,"DEColumn2")
]%%
Row %%=v(@i)=%%, DEColumn1 is %%=v(@DEColumn1)=%%, DEColumn2 is %%=v(@DEColumn2)=%%
%%[
next @i ]%%
%%[ else ]%%
No rows found
%%[ endif ]%%
I'd also recommend using the concat() function to build your URLs:
%%[
var @URL, @brand, @lang
set @lang = AttributeValue("Language")
set @brand = AttributeValue("brandcode")
set @URL= concat("http://",@brand,"xxxxx.com/?ul=", @lang)
]%%
<a href="%%=redirectto(@URL)=%%" alias="test URL"/>link text</a>
Reference:
AMPScript Lookup Examples