Search code examples
sqlsql-servertype-conversionconcatenationscientific-notation

SQL Server concat and convert


In SQL Server I am using the concat function to join two columns. One column is numeric. Because of that after concat, the output shows that number in scientific notation. Is there any way to avoid that scientific notation?

I tried

concat (convert (numbercolumn as varachar), text_column)

but I get an error

concat is not a recognized built in function name


Solution

  • First, you don't need to explicitly convert, so:

    concat(numbercolumn, textcolumn)
    

    If this still converts to exponential, then convert to a decimal first. I'm not sure what you want things to look like but something like:

    concat(convert(decimal(38, 10), numbercolumn), textcolumn)
    

    You can also use format() or str() to convert the value to a string.