Show only students whose first letter of the name does not begins between A to M, show the Gender column and change the value to Female.

ANGELO REYES 1 Reputation point

Pangalan Kasarian
Stephanie N. Female
Tian En Female
Xi Xi Female

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,891 questions
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,563 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Naomi 7,361 Reputation points

    select FirstName, LastName, Gender from dbo.Students
    where FirstName like '[^A-M]%'

    update dbo.Students set Gender = 'Female' where Gender IS NULL

    0 comments No comments

  2. Bert Zhou-msft 3,421 Reputation points

    Welcome to Microsoft T-SQL Q&A Forum!

    Please check this:

    Create table #Student  
     firstname varchar(10),  
     lastname varchar(10),  
     gender Varchar (10) check (gender in ('Female','Male'))  
     insert into #Student values  
    ('Tian',' En' ,'Male'),  
    ('Xi',' Xi' ,'Male'),  
    update #Student set gender='Female' Where firstname not between 'A%' and 'M%'  
    select * from #Student  
    Where firstname not between 'A%' and 'M%'  

    Here is the raw data:
    After you perform the update operation, there are only 4 rows of data left:
    Best regards,
    Bert Zhou

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments