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)
 Getting first 12 digits without the left most 0's

Author  Topic 

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2006-03-28 : 11:46:10
Hi All,

In a Table Sales I have a column UPC(nvarchar) type.
In UPC, the records are like this:
027200008513- UN
000000008544- P2

I just want the part before hyphen - (That is I need the first 12 digits). But I also need the left most 0' to be removed.

In a select statement, I want to get the above records like this:
27200008513
8544


Any quick help would be appreciated.


Thanks,

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2006-03-28 : 11:49:44
Here you go...

--data
declare @t table (v varchar(30))
insert @t
select '027200008513- UN'
union all select '000000008544- P2'

--calculation
select cast(left(v, 12) as bigint) from @t


Ryan Randall
www.monsoonmalabar.com

Ideas are easy. Choosing between them is the hard part.
Go to Top of Page
   

- Advertisement -