Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help creating a Select string 1

Status
Not open for further replies.

RickLiebespach

Programmer
Joined
Sep 29, 2003
Messages
85
Location
US
Using VB.Net...
I have an Access table with the following fields:
Unique_ID - Integer
Completed - Date/Time
User_ID - Integer

I need to get all records for the current user where the Completed field is empty.

I've tried the following but it isn't working right...
I think it's how I'm testing for an empty Date/Time field,
what should it be???

SelectCommand = & _
"SELECT " & _
"Activities.Unique_ID, " & _
"Activities.User_ID, " & _
"Activities.Completed " & _
"FROM Activities " & _
"WHERE Activities.User_ID = " & Session("OCM_User_ID") & _
" AND " & IsDBNull("Activities.Completed")



Rick Liebespach
 
What error or problem are you having now?

Did you try "Activities.Completed" = "" or
"Activities.Completed" = Nothing

 
Code:
"SELECT " & _
         "Activities.Unique_ID, " & _
         "Activities.User_ID, " & _
         "Activities.Completed " & _
 "FROM Activities " & _
 "WHERE Activities.User_ID = " & Session("OCM_User_ID") & _
 " AND Activities.Completed IS NULL"

BTW try reading up on sqlparameters they will prevent something called sql-injection wich can be very dangerous


Christiaan Baes
Belgium

What a wonderfull world - Louis armstrong
 
Yes, I tried those...
part of the problem is I have an ORDER BY clause after the WHERE clause... I didn't mention it because I didn't think it was relevant to the question.

The Select runs but returns an incorrect dataset...
I have 4 records, 3 with a Completed date, and 1 without a Completed date...
I want just that last record.


SelectCommand = & _
"SELECT " & _
"Activities.Unique_ID, " & _
"Activities.User_ID, " & _
"Activities.Completed " & _
"FROM Activities " & _
"WHERE Activities.User_ID = " & Session("OCM_User_ID") & _
" AND " & IsDBNull("Activities.Completed") & _
" ORDER BY Activities.Start_Time DESC "



Rick Liebespach
 
Rick,

Chrissie's SQL should work fine, except that you need to add the ORDER BY clause to it.

Code:
"SELECT " & _
         "Activities.Unique_ID, " & _
         "Activities.User_ID, " & _
         "Activities.Completed " & _
 "FROM Activities " & _
 "WHERE Activities.User_ID = " & Session("OCM_User_ID") & _
 " AND Activities.Completed IS NULL" & _
" ORDER BY Activities.Start_Time DESC "

-Kris
 
may we presume user_id is numeric?

Christiaan Baes
Belgium

What a wonderfull world - Louis armstrong
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top