Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL equivalent to VAL not working
Message
 
À
11/08/2006 17:19:50
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
01144926
Message ID:
01144969
Vues:
16
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform