Pull data from sys.columns in a different database
Add in the database you are looking to query from in front of the sys.columns.

SELECT c.*
FROM &lt;other database name&gt;.sys.columns c
WHERE c.object_id = OBJECT_ID(@tablename);