Stone Cold
Stone Cold

Reputation: 216

Remove duplication of data in SQL Server query

I have a column say TypeOfManager where there will be entries like

TypeOfManager 
-----------------
Sales
Relation
S
R

In this case I want to treat 'R' as Relation and 'S' as Sales.

What will be the syntax of the query in SQL Server.

Upvotes: 1

Views: 124

Answers (3)

Eralper
Eralper

Reputation: 6622

You can create a master table to keep manager types

Create TypeofManager (
 ManagerTypeId char(1) not null,
 ManagerTypeDescription nvarchar(50)
)

Then you can refer to this table from other table data using a foreign key column like ManagerTypeId

You can only store ManagerTypeId and join two table using ManagerTypeId columns

Upvotes: 0

Icarus
Icarus

Reputation: 63970

Select Columna, 
Columnb,
Case when TypeofManager in ('Sales','S') then 'sales'
when TypeofManager in ('Relation','R') then 'Relation'
Else TypeofManager end as TypeOfManager
From yourtable

Columna , columnb above are to be replaced by whatever real columns you need from your table, obviously.

Update

Select count(*), typeofmanager, Columna , columnb from (Select Columna, 
Columnb,
Case when TypeofManager in ('Sales','S') then 'sales'
when TypeofManager in ('Relation','R') then 'Relation'
Else TypeofManager end as TypeOfManager
From yourtable ) x
Group by TypeofManager, Columna, columnb

Upvotes: 2

user978122
user978122

Reputation: 5761

Is there a reason that "S" and "R" can't be changed to "Sales" and "Relation"? If not, just run an update query before you run the main query. If so, then assuming the letters are unique, just do a like "S%" or "R%" query. Or you could write an omni-query that uses Or / And.

Upvotes: 0

Related Questions