Forum Moderators: open

Message Too Old, No Replies

SQL Statement - Please Help

Simple I'm Sure - Just Don't Know The Syntax / Logic

         

dbdev

3:24 pm on May 10, 2006 (gmt 0)

10+ Year Member



Not sure how to do this...

I have 3 tables

1. tblUsers - Fields include UserID and ClientID

2. tblUserSurveyResponses - Fields include UserID and UserSurveyResponses

3. tblClients - Fields include ClientID

The asp.net page has a grid that pulls all clients (select * from clients)

I have a button on the grid that passes the clientID to another page called ViewUserResponses.aspx ( /viewuserresponses.aspx?clientid=22 )

How do I take that ClientID and select all UserSurveyResponses with it given the above mentioned tables?

My logic and way of thinking says this is a 2 part statement.

1st Part - Get all UserID's where ClientID = passed-in-query-string-variable-clientid

2nd Part - Get all UserSurveyResponses where usersurveyresponses.UserID = list-of-userids-from-1st-Part

Obviously if you could help me out with syntax it would be appreciated.

Thanks,

Mike.

ChadSEO

4:29 pm on May 10, 2006 (gmt 0)

10+ Year Member



dbdev,

I don't know ASP/.NET, so I can't help you with the exact syntax, but you could get the results with a single query:

SELECT usr.*
FROM tblUserSurveyResponses usr inner join tblUsers u on usr.UserID = u.UserID inner join tblClients c on u.ClientID = c.ClientID
WHERE c.ClientID = 12345

Of course, the exact syntax would change depending on your table/field names, etc., but hopefully that will point you in the right direction.

Chad