Removing part of a string - SQL Server

Asked

Viewed 5,887 times

2

I have written in a column of the database the name of a file with extension (FILE.txt). I need to show in a SELECT only the FILE instead of FILE.txt

Someone knows how to do?

  • which database? search for its REPLACE function. SELECT REPLACE(', ', '') FROM table..

  • SQL Server 2014.

2 answers

3


  • It worked! Thank you!

1

I’ve made an example that covers a lot of cases. Example: .txt file, .secreto.txt file, .jpeg file.

Declare @campo varchar(100) = 'Arquivo.txt'
select left(@campo,len(@campo) - charindex('.',reverse(@campo)) ) resultado

Browser other questions tagged

You are not signed in. Login or sign up in order to post.