Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • 5
    In Martin Smith's version, one thing to mention is not to include columnName within square brackets [ ]. When columnName is inside square brackets [ ], it'll give null even if the column exists in the table Commented Jun 24, 2019 at 7:57
  • @HemendraSinghChauhan - that's because they aren't part of the name. You will also find that when comparing with the name in sys.columns Commented Jun 24, 2019 at 7:59
  • @MartinSmith didn't knew that, I was using your answer and came across this. Generally I use square brackets during adding columns, so I used them inside COL_LENGTH function too. My code was like this: Alter table Table_Name Add [ColumnName] NVarchar(max) NULL; Select COL_LENGTH('[TABLE_NAME]', '[COLUMN_NAME]') Commented Jun 24, 2019 at 8:08
  • 3
    @AlejandroDG Can you provide an example? I would say, this claim is not true. Commented Mar 9, 2021 at 15:46
  • 5
    @sur - So in what sense would that mean "AlejandroDG is right"? The predicate is IS NOT NULL not >0 Commented Apr 23, 2022 at 5:23