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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Help with trimming characters

Author  Topic 

jose1lm
Yak Posting Veteran

70 Posts

Posted - 2004-09-07 : 17:07:46
How can I trim some of the characters before the results are shown? I can't use RTRIM
because the value doesn't have a static place on where to start the trim. It needs to start trimming off the characters once it reachs the first '-'.

After the trimming fuction, this is how I would like the results to look like:

LinkIds | Filename
1 | 05011
2 | 05027
3 | 011136
4 | 149950



*********************************************

CREATE TABLE [dbo].[active_dwg] (
[LinkIds] [int] NOT NULL ,
[Filename] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Fsize] [bigint] NULL ,
[Fmodified] [datetime] NULL
) ON [PRIMARY]

GO

INSERT INTO active_dwg ([LinkIds],[Filename])
VALUES ('1','05011-00-revL.pdf')
INSERT INTO active_dwg ([LinkIds],[Filename])
VALUES ('2','05027-XX-revD.pdf')
INSERT INTO active_dwg ([LinkIds],[Filename])
VALUES ('3','011136-revB.pdf')
INSERT INTO active_dwg ([LinkIds],[Filename])
VALUES ('4','149950-00-revA-signed.pdf')

GO

SELECT [LinkIds],[Filename]
FROM dbo.active_dwg

GO

DROP TABLE dbo.active_dwg

*********************************************


JLM

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-07 : 17:11:46
this should do it:

select LinkIds, left(Filename, charindex('-', Filename)-1) as TrimmedFileName
from active_dwg

Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -