简体   繁体   中英

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 eg 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM