Forum Moderators: open

Message Too Old, No Replies

Select statement

Beginner Here, need a wee bit of help with ASP

         

Mosha

2:58 pm on Feb 19, 2004 (gmt 0)

10+ Year Member



Hello all

I'm not too sure if this is the place to be, but i'll give it a shot anyways.

I'm new to ASP and well i'm not doin to bad at creating an E-commerce site for a project, but i just can't seem to get the right code for a select statement.
What i'm trying to do (but for some reason failing) is get some records from a table where the records are less than the date NOW but no older than 2 weeks, if anyone out there can help a newbie with this or point me in the right direction to find out then it would be much apprieciated.

Thankyou

Tom

mattglet

3:26 pm on Feb 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"SELECT yourdatefield FROM yourtable WHERE (yourdatefield < getdate()) AND (yourdatefield > (getdate() - 14))"

Code is not tested.

-Matt

WebJoe

5:13 pm on Feb 19, 2004 (gmt 0)

10+ Year Member



Depends on what DB you're on:

Oracle:

SELECT yourdatefield FROM yourtable WHERE (yourdatefield < SYSDATE) AND (yourdatefield > (SYSDATE - 14))

Anything M$ (Access, SQL Server)

SELECT yourdatefield FROM yourtable WHERE (yourdatefield < Now()) AND (yourdatefield > DateAdd("d",-14,Now()))

mattglet

7:53 pm on Feb 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



webjoe-

Your MS statement is incorrect. You need to escape the string to use VBScript.

SELECT yourdatefield FROM yourtable WHERE (yourdatefield < " & Now() & ") AND (yourdatefield > " & DateAdd("d",-14,Now()) & ")

-Matt

WebJoe

3:12 pm on Feb 20, 2004 (gmt 0)

10+ Year Member



You need to escape the string to use VBScript.

That is generally correct, but DateAdd is also an M$-SQL function, not only valid for VB. I tested the SQL on an ADO-connection, and it works just fine

mattglet

5:26 pm on Feb 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



webjoe-
my mistake... just quickly looked at the code, and assumed you were using VB.

-Matt

WebJoe

5:54 pm on Feb 20, 2004 (gmt 0)

10+ Year Member



NP, could have happened to anyone, and I think if anyone looks at this thread later on that doesn't know too much about VB/VBScript and M$-flavored SQL he/she will appreciate the clarification.

Mosha

6:40 pm on Feb 20, 2004 (gmt 0)

10+ Year Member



Agreed webjoe and Matt, i'm new to it all, and i'm happy that it has bin clarified

Cheers

Tom