1)
DECLARE @DefaultCustomerLevel INT = 5
This definitely is not PostgreSQL. Please verify what database you're using. It looks like Microsoft SQL Server. 2) Please don't add extra parts to your question after it's been answered. You should ask another question. However, that sort of "write my SQL for me" is likely to be closed. 3) Please clarify that you also need to declare the data as part of your query so we can give you good answers.