Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LTrim or Trim a table column down.

Status
Not open for further replies.

jojo79

Programmer
Oct 11, 2006
40
US
I have a table called tbl_pul, I import 3000 records weekly. 1 of the columns has data that looks like this "123456789/12345". I am trying to add another column that show just to the left of the "/", so it would add a column with just "123456789". Any ideas, I think I use the LTRIM or just regular Trim???


Thanks for all help
 
you have to do some more work, so here is a complete example

Code:
[COLOR=blue]create[/color] [COLOR=blue]table[/color] blah (v [COLOR=blue]varchar[/color](50))
[COLOR=blue]insert[/color] blah [COLOR=blue]values[/color]([COLOR=red]'123456789/12345'[/color])
[COLOR=blue]insert[/color] blah [COLOR=blue]values[/color]([COLOR=red]'12345345'[/color])
[COLOR=blue]insert[/color] blah [COLOR=blue]values[/color]([COLOR=red]'123456789/33'[/color])
[COLOR=blue]insert[/color] blah [COLOR=blue]values[/color]([COLOR=red]'12345/2345'[/color])


[COLOR=blue]select[/color] [COLOR=blue]case[/color] [COLOR=blue]when[/color] len(v)-len([COLOR=#FF00FF]replace[/color](v,[COLOR=red]'/'[/color],[COLOR=red]''[/color])) = 0 [COLOR=blue]then[/color] v [COLOR=blue]else[/color] [COLOR=#FF00FF]left[/color](v,[COLOR=#FF00FF]charindex[/color]([COLOR=red]'/'[/color],v)-1)
[COLOR=blue]end[/color] v
[COLOR=blue]from[/color] blah

Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
Google Interview Questions





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top