• So will this also work,

    if (select ars.role

    from sys.dm_hadr_availability_replica_states ars

    where ars.is_local = 1) = 2

    begin

    raiserror ('This is not the primary replica.',2,1)

    end