tags:

views:

33

answers:

1

Hi,

We have a utility written in C which reads columns extracted from a database using a stored procedure and outputs a csv file. Simple huh. However when reading a smallint column, it crashes out and not being the greatest C programmer on the planet, I can't nail it. As a workaround can you change the data type in a stored procedure e.g. could the C program "see" the column as a varchar rather than a smallint at runtime?

This is only a monthly process so the impact of doing the type conversion is not an issue.

+2  A: 

Yes, it can. You can do so using either the CAST or CONVERT operator. For instance:

CONVERT(varchar, MyIntColumn) AS MyIntColumn

That will ensure that when the column goes to the client, it goes as a varchar string.

K. Brian Kelley
Best practice would be specify varchar(6) (or another number, but 6 will hold a smallint and sign).
gbn