The RowCount
function returns the number of rows of a rowset in a data extension when used in conjunction with a Lookup function or LookupRows function.
Use case: the
function can be used to determine if the LookupRows function returns any results.RowCount
For example, if I wanted to use the LookupRows function to find any records with the city of San Francisco and only continue to run the AMPscript if it retrieved 1 or more row.
Syntax:
RowCount(1)
1 = Rowset to determine the number of rows
Example:
[dm_code_snippet background="no"]
%%[
set @lookupValue = "whatever"
set @rows = LookupRows("YourDataExtensionName","LookupColumn", @lookupValue)
set @rowCount = rowcount(@rows)
if @rowCount > 0 then
set @row = row(@rows,1)
set @DEColumn1 = field(@row,"DEColumn1")
]%%
DEColumn1 is %%=v(@DEColumn1)=%%
%%[
else
]%% No rows found %%[
endif
]%%
[/dm_code_snippet]
Output:
DEColumn1 is [Value in DE]
Explanation:
In the
example above, we’re using it in conjunction with the LookupRows function to determine if there are any rows in “YourDataExtensionName” — in this hypothetical scenario, a row was found and the AMPscript went through the If/Else function to determine which logic to run.RowCount
Related functions is the LookupRows function and the If/Else function.