INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

SELECT within a SELECT query

SELECT within a SELECT query

(OP)
I am using the WHERE IN within my query but for some reason it is not giving me the results as expected. Here is my code...

CODE -->

strSQL = "SELECT dbo_workitem.id, dbo_workitem.version, dbo_workitem.number, dbo_workitem.action, dbo_workitem.title, dbo_workitem.created_on, dbo_workitem.modified_on, dbo_worker.name, dbo_workitem.type_lookup_id, dbo_workitem.urgency_lookup_id, dbo_workitem.category_tree_value " _
        & "FROM dbo_worker INNER JOIN dbo_workitem ON dbo_worker.id = dbo_workitem.assigned_to_worker_id " _
        & "WHERE dbo_workitem.number IN (SELECT dbo_workitem.number FROM dbo_workitem WHERE modified_on BETWEEN #" & strStart & "# AND #" & strEnd & "# AND dbo_workitem.category_tree_value LIKE 'SCFH/ITU*') " _
        & "ORDER BY dbo_workitem.number, dbo_workitem.version;" 

When I run the select query from within brackets separately then I get a full list of results but using it with the IN statement leaves me sort of results. For example this result should be included but is not, It contains the right criteria...

Quote:

number - modified_on - category_tree_value
92911 - 02/01/2015 11:36:59 - SCFH/ITU\Operations\PC Support
92911 - 05/01/2015 12:52:53 - SCFH/ITU\Operations\PC Support
92911 - 13/01/2015 02:00:56 - SCFH/ITU\Operations\PC Support

I also end up getting dates not within the range requested. So modified_on between #01/01/2015# and #31/01/2015# brings up dates in 2014.

Do you have any suggestions? Many thanks...








RE: SELECT within a SELECT query

Did you try it without the inner Select:

CODE

strSQL = "SELECT dbo_workitem.id, dbo_workitem.version, dbo_workitem.number, dbo_workitem.action, dbo_workitem.title, dbo_workitem.created_on, dbo_workitem.modified_on, dbo_worker.name, dbo_workitem.type_lookup_id, dbo_workitem.urgency_lookup_id, dbo_workitem.category_tree_value " _
        & "FROM dbo_worker INNER JOIN dbo_workitem ON dbo_worker.id = dbo_workitem.assigned_to_worker_id " _
        & "WHERE dbo_workitem.number IN (SELECT dbo_workitem.number FROM dbo_workitem WHERE modified_on BETWEEN #" & strStart & "# AND #" & strEnd & "# AND dbo_workitem.category_tree_value LIKE 'SCFH/ITU*') " _
        & "ORDER BY dbo_workitem.number, dbo_workitem.version;" 

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

RE: SELECT within a SELECT query

(OP)
I have thanks but record 92911 still does not appear in the result.

RE: SELECT within a SELECT query

Be sure to check the regional settings on your computer dd/mm/yyyy and not mm/dd/yyyy.

RE: SELECT within a SELECT query

(OP)
That is set as DD/MM/YYYY

RE: SELECT within a SELECT query

The record 92911 - does the dbo_worker.id = dbo_workitem.assigned_to_worker_id ?
And what are the values for strStart and strEnd ?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close