Wildcards in SQL server GRANT statements

Status
You're currently viewing only Gandalf007's posts. Click here to go back to viewing the entire thread.

Gandalf007

Ars Tribunus Angusticlavius
6,961
Subscriptor
Does SQL Server have anything like PostgreSQL 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.
 
Status
You're currently viewing only Gandalf007's posts. Click here to go back to viewing the entire thread.