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
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello.
I have a table with a column of strings. I need to display the number of spaces in the string column in a new column. For example, 'jA kk qa', in a new column, display 2.
How do I do this? Thanks in advance.
Hi @15431565
Try this query.
create table test(col varchar(100));
insert into test values
('jA kk qa'),
('N lta'),
('KK Dt'),
('U PF GH'),
('V bag ha'),
('jkj sa cc as sk');
select *,len(col) - len(replace(col,' ','')) as spacenums from test;
Output:
Best regards,
Percy Tang