MyHeadHurts
MyHeadHurts

Reputation: 1562

QueryString into SQL selectdate= statement

Alright so I have a page that the user types in a date hits a button and a querystring is placed in my other page. I want this date that they typed to be placed into my sql statement. I am reading the querystring useing javascript at this point, but i cannot get it into my sql statement.

<!--
function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}
}


var rundate = querySt("rundate");

document.write(rundate);
document.write("<br>");
-->

I was told to use a declare and set statement but i kept getting errors.. Any ideas I have been stuck on this for 2 days, im sure you all know how that feels.

selectdata= "SELECT............ Having dbo.BOOKINGS.BOOKED = CONVERT(INT, DATEADD(dd, DATEDIFF(dd, 0, '11-04-2010'), 0))+2

Upvotes: 0

Views: 283

Answers (1)

rob
rob

Reputation: 10117

Try breaking the problem down into parts. Ignore the sql stuff for now, just make sure your function is getting the string correctly and breaking out the "rundate" parameter. That part looks ok, as long as the line window.location.search; is actually getting a correct string.

Two suggestions that probably don't apply to your problem, but are good practice: use alert() rather than document.write(), and put "var" before local variables so they don't pollute global namespace. That is:

var gy = hu.split("&");

etc.

Upvotes: 1

Related Questions