Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip first letters of all values returned from a sql server database

Tags:

sql

as topic says, I don't want to return the first two letters in the return values just an example: select companyname from companies returns companyX

Can I write a query that returns panyX instead?

Thanks in advance

like image 697
Peter Avatar asked Jun 10 '10 06:06

Peter


People also ask

How do I ignore the first character in SQL?

To delete the first characters from the field we will use the following query: Syntax: SELECT SUBSTRING(string, 2, length(string));

How do I skip top 10 records in SQL?

Let us see the following example which I have written with the help of a sample database AdventureWorks. In the following table, we can skip the top 100 rows by just using the keyword OFFSET and not specifying the FETCH keyword.

How do I ignore text in SQL?

Any text between /* and */ will be ignored.


2 Answers

select right(companyname, len(companyname)-3) as companyname will do the thing (this should work for microsoft T-SQ, see more string functions here )

like image 100
naivists Avatar answered Sep 21 '22 10:09

naivists


Since you don't say what RDBMS you're using, here is an ANSI-compliant answer:

SELECT SUBSTRING(mycolumn,3,CHARACTER_LENGTH(mycolumn))
like image 33
mechanical_meat Avatar answered Sep 22 '22 10:09

mechanical_meat