Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL equivalent to VAL not working
Message
 
To
11/08/2006 17:19:50
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01144926
Message ID:
01144969
Views:
22
Tracy,

Here's a function you can add to your database to strip the letters out of the field and return an integer. I've also included two queries that do effectively the same thing. I don't know which would be more efficient in your case (or if either will be acceptable):
create function dbo.StripLetters
(
	@value varchar(10)
)
returns int
as
begin
	declare @letter char(1)

	set @letter = 'A'

	while (@letter <> 'Z')
	begin
		set @value = replace(@value, @letter, '')

		set @letter = char(ascii(@letter) + 1)
	end

	return convert(int, @value)
end
go
create table oMain (Number char(10))

insert into oMain values ('1058')
insert into oMain values ('1058A')
insert into oMain values ('1167')
insert into oMain values ('2054B')
insert into oMain values ('3001')
insert into oMain values ('3000A')
insert into oMain values ('22A')

select * 
	from oMain
	where case isnumeric(number)
			when 1 then convert(int, number)
			else dbo.StripLetters(number)
		end between 1100 and 3000

select *
	from oMain
	where dbo.StripLetters(number) between 1100 and 3000

drop table oMain
drop function dbo.StripLetters
HTH,
Chad
>Some results that should not be included were returned:
>
>111
>21
>217
>210
>...
_________________________________
There are 2 types of people in the world:
    Those who need closure
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform