Peter
Peter

Reputation: 83

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

I don't want to return the first three letters in the return values. An example:

select companyname from companies 
-- returns companyX

Can I write a query that returns panyX instead?

Upvotes: 8

Views: 14198

Answers (6)

RAJNISH KUMAR
RAJNISH KUMAR

Reputation: 11

SELECT SUBSTR(COMPANYNAME,3) 
FROM COMPANIES;

Upvotes: 0

Venaikat
Venaikat

Reputation: 197

you can solve your issue by using following queries,

 --> select substring([image],4,len([image])) from dbo.emp

and

 --> select replace([image],'ima','') from dbo.emp

Thanks

Venkat

Upvotes: 0

Sploofy
Sploofy

Reputation: 503

SELECT SUBSTRING(companyname, 3, len(companyname) - 2)
  FROM companies

Upvotes: 0

naivists
naivists

Reputation: 33511

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

Upvotes: 11

mechanical_meat
mechanical_meat

Reputation: 169304

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

SELECT SUBSTRING(mycolumn,3,CHARACTER_LENGTH(mycolumn))

Upvotes: 4

griegs
griegs

Reputation: 22760

Here is a bunch of string manipulation stuff for sql

Tutorial 4: SQL functions

Upvotes: 0

Related Questions