If you get a null back try this query:
select [COLUMN_NAME] from information_schema.columns where TABLE_NAME='TABLENAME'
Question
When executing a query using Invoke-Sqlcmd
, if no rows are returned, the result is just $null
.
I wondering if it's possible to still return the column headers, but with no data. This would make it consistent with a query which did return rows.
Is there an easy way to do this?
Solution
If you get a null back try this query:
select [COLUMN_NAME] from information_schema.columns where TABLE_NAME='TABLENAME'
OTHER TIPS
Check for $null - if $null then call this query:
set fmtonly on
select * from yourTable where 1=0