• You can test the result set, if the count is 0 then don't execute the code, see the code!

    😎

    DECLARE @RES TABLE

    (

    is_hidden BIT NULL

    ,column_ordinal INT NULL

    ,name SYSNAME NULL

    ,is_nullable BIT NULL

    ,system_type_id INT NULL

    ,system_type_name SYSNAME NULL

    ,max_length INT NULL

    ,precision INT NULL

    ,scale INT NULL

    ,collation_name SYSNAME NULL

    ,user_type_id INT NULL

    ,user_type_database SYSNAME NULL

    ,user_type_schema SYSNAME NULL

    ,user_type_name SYSNAME NULL

    ,assembly_qualified_type_nameSYSNAME NULL

    ,xml_collection_id INT NULL

    ,xml_collection_database SYSNAME NULL

    ,xml_collection_schema SYSNAME NULL

    ,xml_collection_name SYSNAME NULL

    ,is_xml_document BIT NULL

    ,is_case_sensitive BIT NULL

    ,is_fixed_length_clr_type BIT NULL

    ,source_server SYSNAME NULL

    ,source_database SYSNAME NULL

    ,source_schema SYSNAME NULL

    ,source_table SYSNAME NULL

    ,source_column SYSNAME NULL

    ,is_identity_column BIT NULL

    ,is_part_of_unique_key BIT NULL

    ,is_updateable BIT NULL

    ,is_computed_column BIT NULL

    ,is_sparse_column_set BIT NULL

    ,ordinal_in_order_by_list BIT NULL

    ,order_by_is_descending BIT NULL

    ,order_by_list_length BIT NULL

    ,tds_type_id INT NULL

    ,tds_length INT NULL

    ,tds_collation_id INT NULL

    ,tds_collation_sort_id INT NULL

    )

    INSERT INTO @RES

    EXEC sp_describe_first_result_set N'SELECT * FROM SYS.OBJECTS'

    SELECT COUNT(*) FROM @RES