select FirstName, LastName, Gender from dbo.Students
where FirstName like '[^A-M]%'
update dbo.Students set Gender = 'Female' where Gender IS NULL
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Q8
Pangalan Kasarian
Stephanie N. Female
Tian En Female
Xi Xi Female
select FirstName, LastName, Gender from dbo.Students
where FirstName like '[^A-M]%'
update dbo.Students set Gender = 'Female' where Gender IS NULL
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:
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.