I have imported a table to my database, and to get the number of columns and assign it to a variable I do
SELECT @HowManyColumns = COUNT(COLUMN_NAME)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE (TABLE_NAME = @table_name )
But it keeps telling that the count is 0!
If I do the same for other tables it works!
I have found that the column count of the table that is not working is more than 40 columns, Why is it not working…
The data is this
Since tables w/o columns don’t exists, that can only mean that the WHERE clause is not satisfied. In other words, the table named as the value of @table_name does not exists. Since you say ‘sometimes it work, and some does not’ that would immediately point toward case sensitive deployments. Make sure you always use the correct name for the table, with the proper case, so your code work correctly on servers which are deployed with a case sensitive collation.