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
2022-03-24T08:07:31.077+00:00

Q8
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.
13,361 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,601 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Naomi 7,366 Reputation points
    2022-03-24T13:38:39.197+00:00

    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
    2022-03-25T03:05:17.48+00:00

    Hi,@ANGELO REYES
    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  
    ('Pangalan','Kasarian','Male'),  
    ('Stephanie','N.','Male'),  
    ('Tian',' En' ,'Male'),  
    ('Xi',' Xi' ,'Male'),  
    ('HXw','ER','Male'),  
    ('APR','MKK','Female'),  
    ('EXw','ER','Male'),  
    ('GPR','MKK','Female')  
    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:
    186786-image.png
    After you perform the update operation, there are only 4 rows of data left:
    186698-image.png
    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