1

my table is like:

id |  name |   subject
-------------------
1  | kil   |   btech
2  | Jim   |   BACHELOR OF TECHNOLOGY
3  | Joe   |   Btech
4  | Ruth  |    MCA
5  | priya |   Master in comp application
6  | dev   |   MASTER IN COMPUTER APPLICATION
7  | sen   |   Master in Computer Application

how to group related field value into a single name such as:

id |  name  |  subject
-------------------
1  | kil    |  BACHELOR OF TECHNOLOGY
2  | Jim    |  BACHELOR OF TECHNOLOGY
3  | Joe    |  BACHELOR OF TECHNOLOGY
4  | Ruth   |  Master in Computer Application
5  | priya  |  Master in Computer Application
6  | dev    |  Master in Computer Application
7  | sen    |  Master in Computer Application

2 Answers 2

2

Create a table With Synonyms of the same course. And then join These two tables to get the result

(this might be the easiest way since you can add more Synonyms later without code change)

Like this

CREATE TABLE dbo.t_Synonyms
(
    SeqNo INT IDENTITY(1,1),
    FalseText VARCHAR(255),
    DisplayText VARCHAR(255)
)

INSERT INTO t_Synonyms(FalseText,DisplayText)
VALUES('BTEC','BACHELOR OF TECHNOLOGY'),
('B.TECG','BACHELOR OF TECHNOLOGY'),
('MCA',' Master in Computer Application'),
    ('Master in comp application',' Master in Computer Application')
SELECT
    YT.ID,
    YT.NAME,
    [SUBJECT] = ISNULL(TS.DisplayText,YT.[SUBJECT])
    FROM YourTable YT
        LEFT JOIN t_Synonyms TS
            ON LTRIM(RTRIM(YT.[SUBJECT])) = LTRIM(RTRIM(TS.FalseText)) 
Sign up to request clarification or add additional context in comments.

2 Comments

@Schuere SQL is case insensitive, so you don't need that
The default options for installation of SQL Server will tend to leave you with a server whose default collation is case insensitive. That a) doesn't mean that you'll never encounter a case sensitive collation when working with SQL Server and b) definitely doesn't mean that "SQL is case insensitive".
0
update mytable set subject = case when subject = 'btech' or subject = 'Btech' then 'BACHELOR OF TECHNOLOGY' when subject = 'MCA' or subject = 'Master in comp application' then 'Master in Computer Application' end where subject = 'btech' or subject = 'Btech' or subject = 'MCA' or subject = 'Master in comp application'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.