user188827
user188827

Reputation:

Can SQL Server do a type conversion at run-time

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.

Upvotes: 0

Views: 61

Answers (1)

K. Brian Kelley
K. Brian Kelley

Reputation: 1667

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.

Upvotes: 2

Related Questions