Does SQL Server have anything like PostgreSQL
And then (after reviewing the output, which is one line of GRANT SELECT ON schema.table1, schema.table2, ... TO username), I'd copy and paste it into the prompt. No cursor/loop needed.
string_agg()? In postgres, the equivalent information_schema query would be:
SQL:
SELECT 'GRANT SELECT ON '
|| string_agg(quote_ident(table_schema) || '.' || quote_ident(table_name), ', ')
|| ' TO username;'
FROM information_schema.tables
WHERE table_name LIKE 'Product%';
OR table_name LIKE 'Sales%';
And then (after reviewing the output, which is one line of GRANT SELECT ON schema.table1, schema.table2, ... TO username), I'd copy and paste it into the prompt. No cursor/loop needed.