I'm trying to pull year data from a table, but the results show thousand separator e.g. 2021 become 2,021. What should I do to remove the comma? Here's a simple version of my query:
select table.year from table
-Update-
The datatype is smallint, and the syntax below worked. Thank you!
SELECT CAST(year AS varchar(4)) AS year FROM yourTable;
CodePudding user response:
First and foremost, check the datatype of your column.
If you're storing year only, it might be a simple int
OR
just replace the comma
SELECT REPLACE(table.year,',','') from table
OR type convert it
SELECT year(CAST( table.year as datetime )) from yourtable
CodePudding user response:
What you are seeing could be due to that, for whatever reason, the year
column of your table happens to be decimal. Or, it could be that your SQL tool/client likes to format all numbers with thousands separators. In either case, the following workaround might work:
SELECT CAST(year AS varchar(4)) AS year
FROM yourTable;