Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

wrong column size with SQLDescribeCol

Status
Not open for further replies.

lupien1

Programmer
Mar 1, 2005
34
CA
To dynamically set the length of a variable (Code in C) to store data, i use the ODBC API function SQLDescribeCol. When a smalldatetime column type from SQLServer is treat by SQLDescribeCol, the COLSIZE return by the function is 16 when YYYY-MM-DD HH:MM:SS contain 19 characters. This case overload my variable with a crashing result of my program.

Is it a known problem and how can it be fixed?

Thank you!
 
There is no problem. The number of characters displayed in a datetime field (or smalldatetime field) doen't matter. Dates and times are not stored the same way they are viewed. If you need to move it to a static number of columns do a convert or cast on your datetime field.

smalldatetime uses 4 btyes for storage
datetime uses 8 bytes for storage

Code:
select convert(varchar(20), DateTimeColumn)
from table1

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
There is something i don't understand. When Datetime type is treat by SQLDescribeCol, the Colsize return is 23 "YYYY-MM-DD HH:MM:SS.000". Why Datetime is correct but not smalldatetime?

I can't use your SELECT suggestion because our function build a structure dynamically with all table retreive by a previous SQLTables call.

Thank you!
 
No idea. I'd check with the C folks in the C forums.

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top