• Your function returns 1 if any of the columns exists in the table, not if all columns exists in the table.

    But it is not going to work out anyway. If any of the columns are missing, the stored procedeure will not compile, as there is - thankfully! - no deferred name resolution on column names.

    Now for the real question: why do you want to do this at all? Maybe you have a good reason - but the solution may be different.

    [font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]