views:

24

answers:

1

Hello,

I am writing a basic DBMS package and I am trying to retrieve the column length. This is the query I am using to retrieve the infomation:

SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH 
FROM INFORMATION_SCHEMA.Columns 
WHERE TABLE_NAME = 'testVariables'

This works fine, no issues except for CHARACTER_MAXIMUM_LENGTH returns -1 all the time, When I use SQL Management Studio it says the column length is 16...

Any ideas?

Cheers, Joel

+1  A: 

Take a look at look at books online and you will discover that the value -1 for CHARACTER_MAXIMUM_LENGTH means the data type is either XML of a large-value type.

See COLUMNS

John Sansom
Hello, Thanks for the answer. I read that when researching why It was going wrong - but it should return the value 16 as the column is nVarchar(16) - or am I being thick?Cheers, Joel
JHarley1
I just created a test table with a column nVarchar(16) and it shows up correctly. Are you sure you're in the right database context. Or don't have 2 tables of that name in different schemas?
Martin Smith
or the datatype is an INT, DATETIME etc. - just something that's nor (N)VARCHAR, nor (N)CHAR
marc_s
Hey, yeah I think the problem was the way the table was defined, I will try delete and re-create the table. Cheers, Joel
JHarley1