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
 SQL Server Development (2000)
 Access Val() function equivalent

Author  Topic 

supernova
Starting Member

1 Post

Posted - 2007-04-27 : 11:19:38
Hi,

I am presently transferring a query from Access into SQL Server. A field in the Access query contains the function Val() which takes the first value it sees within a string until it reaches a non-numeric value. I was wondering, is there such a function in SQL Server?

Thanks

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-27 : 11:53:12
There is no built-in function for this, but not too difficult to build.

-- prepare sample data
declare @t table
(
a varchar(100)
)

insert @t
select '173hs' union all
select '58d' union all
select 'aa' union all
select '863'

-- actual query
select
left(a, patindex('%[^0-9]%', a)-1) as a
from @t
where
patindex('%[^0-9]%', a) > 1
union all
select
a
from @t
where
patindex('%[^0-9]%', a) = 0


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -