How to make case-sensitive comparison in sql?

Just started a SQL tutorial for beginners. Now I am doing some exercises, and I would like to know how to change the name.

If you look here: you will see that I created a name, surname, title, age and salary. And I wrote letters in a short letter. How can I change it to capital letter?

http://tinypic.com/r/amtpgm/3

I tried using this:

update mytablename 
set firstname = 'Firstname'
where firstname = 'firstname'

But later I realized that this would not work.

thanks

====

additional question:

I also notice that if I wrote with spaces, they did not recognize it. This is the first part to be displayed. Do you know why this is happening? Thanks

create table myemployees_tr0214
(First Name varchar(20),
Last Name varchar(20),
Title char(5),
Age number(3),
Salary number(6,10));

===========

Thank you for all your submissions. I tried this when renaming "Firstname" to "Fname" and it did not work. Did I miss something?

alter table myemployees_tr0214
rename column Firstname to Fname;
+3
8

, . UPDATE, . , SQL .

, , ALTER TABLE . MS-SQL , , SQL DDL- .

, MS-Access, , , . " " SQL [ ]

+1

:

UPDATE mytablename SET firstname = CONCAT(UCASE(MID(firstname,1,1)),MID(firstname,2));

, :)

+3

-, , . , , , , SQL. : , , , , .

. . , " SQL", , , .., , , , , , .

, -, SQL , , , , . , , + .

, camelCasing, : FirstName, LastName

+2
update mytablename set firstname = 'Firstname'; where firstname = 'firstname';

firstname. , , firstname. , ( ).

MS Access SQL-, .

SQL ALTER TABLE, .

+1

MS SQL Server...

[] :

create table myemployees_tr0214 (
  [First Name] varchar(20),  --here
  [Last Name] varchar(20),  --here
  Title char(5),
  Age number(3),
  Salary number(6,10)
);

"firstname" "Firstname", sp_rename MS SQL Server.

"firstname", .

update mytablename 
set firstname = 'Firstname'
where firstname COLLATE Latin1_general_Bin = 'firstname' COLLATE Latin1_general_Bin
+1

mysql: http://dev.mysql.com/doc/refman/5.0/en/charset-binary-op.html

BINARY . , . BINARY ,

mysql> SELECT 'a' = 'A';
        -> 1
mysql> SELECT BINARY 'a' = 'A';
        -> 0
mysql> SELECT 'a' = 'a ';
        -> 1
mysql> SELECT BINARY 'a' = 'a ';
        -> 0
+1

- , id,

update mytablename set firstname = 'Firstname' where id = 1

now what can be used as a unique identifier for a string is a huge discussion of natural vs surrogate . use what you think is best suited for your example, but I'm a supporter of surogate keys, as each natural key has the ability to change.

0
source

This may need to be optimized for more, but it will even allow you to upgrade the version of MULQL called mulitple

select 'mary ellen' as firstname into #test
insert into #test select 'Nathan'


select 
Case when patindex('% %',firstname) >0 then
upper(left(firstname,1)) --first letter
+ rtrim(substring(firstname,2,patindex('% %',firstname)-1)) --whole firstname
+ ' ' -- space
+ Upper(substring(firstname,patindex('% %',firstname)+1,1)) --first letter last name
+  rtrim(substring(firstname,patindex('% %',firstname)+2, len(firstname)))
else
upper(left(firstname,1)) + substring(firstname,2,len(firstname))
end as firstname
from #test


update #test
set firstname = Case when patindex('% %',firstname) >0 then
upper(left(firstname,1)) --first letter
+ rtrim(substring(firstname,2,patindex('% %',firstname)-1)) --whole firstname
+ ' ' -- space
+ Upper(substring(firstname,patindex('% %',firstname)+1,1)) --first letter last name
+  rtrim(substring(firstname,patindex('% %',firstname)+2, len(firstname)))
else
upper(left(firstname,1)) + substring(firstname,2,len(firstname))
end 
0
source

Source: https://habr.com/ru/post/1713942/


All Articles