Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 delete part of a field

Author  Topic 

a.ashabi
Posting Yak Master

117 Posts

Posted - 2008-12-04 : 19:14:11
Hi.I have a field with these values:

PropelLemo35728
77003615133
Electro-Mi16292

I want to delete the last 5 digits from it.to have :

PropelLemo
770036
Electro-Mi

what should i do?
thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-04 : 19:27:07
SELECT LEFT(Column1, DATALENGTH(Column1) - 5)
FROM YourTable

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2008-12-11 : 04:10:31
select SUBSTRING(column,1,LEN(column)-5) FROM table

Jai Krishna
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-12-11 : 08:01:54
quote:
Originally posted by tkizer

SELECT LEFT(Column1, DATALENGTH(Column1) - 5)
FROM YourTable

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



It depends on the datatype of the column

declare @t table(data char(20))
insert into @t
select 'PropelLemo35728' union all
select '77003615133' union all
select 'Electro-Mi16292'

SELECT data,LEFT(data, DATALENGTH(data) - 5)
FROM @t

SELECT data,LEFT(data, LEN(data) - 5)
FROM @t


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-11 : 15:59:51
Of course and it also depends on your business requirements.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2008-12-11 : 17:43:17
quote:
what should i do?



Tell the business bozos to get the data in a normalized form?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -