• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

SQL data has commas in it

I have columns with imbedded commas (like company name, etc.) and it kills my sql select when compounding multiple columns together;

SELECT  lastname + ' ' + firstname + '  ' + Companyname as LongName

The result is truncated where there is a comma in the company name.  It's not uncommon to use commas in names and addresses.  Surely there is a way to return the entire value.
1 Solution
What are your field lengths? Try -

SELECT  CAST(lastname + ' ' + firstname + '  ', varchar(500)) + CAST(Companyname as varchar(500) as LongName
Scott PletcherSenior DBACommented:
SQL itself doesn't have a problem with commas in the data.  The problem is very likely on the receiving/display end.
SharathData EngineerCommented:
Your query will not trunacte the characters of your firstname. lastname or companyname.
SELECT  lastname + ' ' + firstname + '  ' + Companyname as LongName
As ScottPletcher, there may be problem by recieving application. check that one. if you think, you have issues while executing in SSMS, post the issue.
Anthony PerkinsCommented:
If the problem is that you are exporting to a CSV file, than there are ways to workaround that.  But this is unrelated to SQL Server.
larksysAuthor Commented:
It appears that you guys are correct.  Thanks.  It has to do with the coldfusion valuelist function.

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now