Table data has a field 'Name' with data like this
| Names | State |
| ------------ | ------------ |
| Sometimes | WA |
| Some times | KS |
| Som etimes | NY |
| ABCDE Corp | CA |
| SSS Corp | WA |
| SSS Corporation | VI |
| ABCDE | CA |
| ABCDE Corporation | NJ |
Need to consolidate names dynamically
Names | State |
---|---|
Sometimes | WA |
Sometimes | KS |
Sometimes | NY |
ABCDE Corp | CA |
SSS Corp | WA |
SSS Corp | VI |
ABCDE Corp | CA |
ABCDE Corp | NJ |
Tried below query but no luck.
SELECT * FROM [Table1]
WHERE LEFT([Name], 5) IN
(
SELECT LEFT([Name], 5)
FROM [Table1]
GROUP BY LEFT([Name], 5)
HAVING COUNT(*) > 1
)
Any alternate suggestions to derive common name dynamically in SQL Server? Thanks in advance
2条答案
按热度按时间nlejzf6q1#
pdsfdshx2#
This will replace "Corporation" by "Corp", remove all blank except those before "Corporation".