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)
 Find age between .....

Author  Topic 

ramone_johnny
Starting Member

35 Posts

Posted - 2011-06-30 : 10:12:02
Hey guys,
How can I change this bit of code below to find ages "between" or around a certain number?

if profile_prefage <> "" then
strSQL = strSQL & " AND m.mem_age = " & SQLNumber(profile_prefage) & " "
end if

So if profile_prefage = 25 I get results from say, 20 to 30 (5 each way)

Complete newbie. Please forgive me for having to ask such stupid questions...

ramone_johnny
Starting Member

35 Posts

Posted - 2011-06-30 : 10:20:38
Heres what I came up with...can this be done any better?

if profile_prefage <> "" then

profile_prefage1 = profile_prefage - 5
profile_prefage2 = profile_prefage + 5

strSQL = strSQL & " AND m.mem_age BETWEEN " & SQLNumber(profile_prefage1) & " AND " & SQLNumber(profile_prefage2) & " "
end if

Complete newbie. Please forgive me for having to ask such stupid questions...
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-06-30 : 10:23:19
This?

strSQL = strSQL & " AND m.mem_age between " & SQLNumber(profile_prefage) & "-5 AND " & SQLNumber(profile_prefage) & "+5" & " "



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ramone_johnny
Starting Member

35 Posts

Posted - 2011-06-30 : 10:23:24
This done the same thing!

if profile_prefage <> "" then
strSQL = strSQL & " AND m.mem_age BETWEEN " & SQLNumber(profile_prefage) -5 & " AND " & SQLNumber(profile_prefage) + 5 & " "
end if

Guess that should do it :)

Complete newbie. Please forgive me for having to ask such stupid questions...
Go to Top of Page

ramone_johnny
Starting Member

35 Posts

Posted - 2011-06-30 : 10:23:55
Thanks WebFred, you just beat me to it! :0)

Complete newbie. Please forgive me for having to ask such stupid questions...
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-06-30 : 10:24:30
OMG again too late!



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -