Why is Request.QuerySting being treated as a number?

J

Jules

Hi:

I have the following:

NRYear = Request.QueryString("nryear")

which I assumed would result in NRYear containing a string.

However, when I concatenate it with "1/1/", I get "1/1/+2003" as if
the NRYear is a number.

Ultimately, this will go in a SQL string such as

SQL = "Select * from newsreleases where nrdate between 1/1/2003 and
12/31/2003;"

and I want the year to come from the Request.QueryString as the user's
selection.

Help!!! Running out of ideas,

Jules
 
R

Ray at

And how are you concatenating? You're apparently also concatenating a "+"
in there. Either that, or the + is in your querystring value.

Ray at work
 
A

Aaron Bertrand - MVP

However, when I concatenate it with "1/1/", I get "1/1/+2003" as if
the NRYear is a number.

Could you possibly show the code you are using to concatenate?
 
B

Bob Barrows

That does not happen to me.

sYear = "2003"
Response.write "1/1" & sYear

results in the expected "1/1/2003"

Please show us how to reproduce your problem.

Bob Barrows
 
J

Julian Rickards

OK, here is the code:

NRYear = Request.QueryString("nryear")
StartOfYear = "11/1/" & NRYear
EndOfYear = "12/31/" & NRYear
SQLWhereString = "newsreleases.nrdate Between " & StartOfYear & " And "
& EndOfYear

Response.Write SQLWhereString

and the Response.Write spits out (exactly as pasted below):

newsreleases.nrdate Between 11/1/+2003" And 12/31/+2003"


I am building a search form where the user selects the year and I am
trying to build a between clause from the year selected.

Jules
 
J

Julian Rickards

HI:

I hope this isn't being double posted - I tried to post a response
directly to DevDex but it hasn't appeared after about 30 minutes of
waiting.

OK, here is the code:

NRYear = Request.QueryString("nryear")
StartOfYear = "1/1/" & NRYear
EndOfYear = "12/31/" & NRYear
SQLWhereString = "newsreleases.nrdate Between " & StartOfYear & " And "
& EndOfYear

Response.Write SQLWhereString


The output from the response.write is (copied and pasted exactly as
output):

newsreleases.nrdate Between 1/1/+2003" And 12/31/+2003"

So, as you can see, there is a plus (+) at the beginning and a double
quote at the end of each NRYear.

Jules
 
R

Ray at

Well, your plus is in your querystring then. Your URL must look like this:


yoursite.com/page.asp?nryear=+2003 or yoursite.com/page.asp?nryear=%2B2003

You'll see this if you do:

RESPONSE.WRITE REQUEST.QUERYSTRING("NRYEAR")
RESPONSE.END


Ray at work
 
R

Ray at

Oh, and also the quote is in your querystring too. I forgot about that
part.

Ray at work
 
B

Bob Barrows

As Ray suggested, show us what you get when you do this:

Response.Write NRYear

Bob Barrows
 
D

Don Verhagen

In Julian Rickards <[email protected]> typed:
: OK, here is the code:
:
: NRYear = Request.QueryString("nryear")


Add a Response.Write ("NRYear = " & NRYear)

To see what is actually in the QueryString. I think you are assuming it's a
concatination problem when it could very well be a data problem.

Don



: StartOfYear = "11/1/" & NRYear
: EndOfYear = "12/31/" & NRYear
: SQLWhereString = "newsreleases.nrdate Between " & StartOfYear & "
: And " & EndOfYear
:
: Response.Write SQLWhereString
:
: and the Response.Write spits out (exactly as pasted below):
:
: newsreleases.nrdate Between 11/1/+2003" And 12/31/+2003"
:
:
: I am building a search form where the user selects the year and I am
: trying to build a between clause from the year selected.
:
: Jules
:
:
: Don't just participate in USENET...get rewarded for it!
 
H

Hannibal

naaa, i suspect that NRYear is coming through with the +
Why don't you copy the url(that is, the pagename and everything after) for
us and paste it here...
 
G

Guinness Mann

OK, here is the code:

NRYear = Request.QueryString("nryear")
StartOfYear = "11/1/" & NRYear
EndOfYear = "12/31/" & NRYear
SQLWhereString = "newsreleases.nrdate Between " & StartOfYear & " And "
& EndOfYear

Response.Write SQLWhereString

and the Response.Write spits out (exactly as pasted below):

newsreleases.nrdate Between 11/1/+2003" And 12/31/+2003"

Sounds to me like NRYear is " 2003", not "2003".

-- Rick
 
J

Julian Rickards

OK, I have figured it out but it was something I would never have
suspected.

The year was coming from a select list on the search page which was
generated by a for loop:

currentyear = Right(Date, 4)
for i=2000 to currentyear
Response.write "<option value=" & chr(34) & i & chr(34) & ">" & i
next


The variable "i" was being used by the for loop presumably as a number
so that it may be incremented.

When a year is selected, it is added to the QueryString as nryear=2003.
Because my book (a poor one but all I have) tells me that
Request.QueryString will bring in 2003 as a string, I didn't think it
had to be converted from a number into a string but for some reason,
because currentyear is a number, it seems that the numeric property of
nryear was being carried through.

When I changed the currentyear statement to

currentyear = Right(CStr(Date), 4)

all the problems cleared up.

Yes, the problem was in the query string but appears to be a function of
the property of nryear when the option loop was being generated.

Thanks for your help,

Jules
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top