I am doing something that requires me to build a dynamic sql statement as I loop through certain user tables in sys.objects. The issue I am running into is that some tables have reserved words or special characters or whatever else that requires me to wrap
that table name around square brackets. Now, I know I can build the square brackets around the table name when I build my dynamic sql, but I thought I remember reading somewhere there is another way to do this using some function or something.
In other words, is there another way to get this result set without typing '[' and ']'?
select top 10 '[' + name + ']' from sys.objects where type = 'U'
The reason why I ask is because in that article that I think I remember reading, there was a reason why you shouldn't do it this way. But, I could be totally off in my memory.
View Complete Post