sql sample with declaring table, variable and loop