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)
 Trim Columns

Author  Topic 

duhaas
Constraint Violating Yak Guru

310 Posts

Posted - 2006-08-30 : 09:09:02
If I have a temp table with a colum of data that is currently either 2,3,4,5,6 numbers long, and I want to trim the colum so that all value are 2 numbers long, the first 2 numbers how would i do that? Example

current

IDNUMBER
10
23445
999
0987
3432

i want

idnumber
10
23
99
09
34

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-08-30 : 09:10:30
UPDATE TempTable SET IDNUMBER = LEFT(IDNUMBER, 2)

Better is to insert the corrected value from start.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Vivaldi
Constraint Violating Yak Guru

298 Posts

Posted - 2006-08-30 : 09:12:28
Select LEFT(cast(idnumber as varchar(10)),2)

________________________________________________
I am a man, I can change, if I have to, I guess.
Go to Top of Page

duhaas
Constraint Violating Yak Guru

310 Posts

Posted - 2006-08-30 : 09:13:45
I appreciate the quick reply, my issue with doing it from the start is its just more manual work. Today I have to import the data into excel, trim down the colum first, and than import the data. Dont even get me started on why the data doesnt show up right to begin with, arrgghhhh.
thanks again, you guys rock
Go to Top of Page
   

- Advertisement -