Help in Generate Specefic Sql Query

Happy Neew Year to all.

Can Anybody help me with next.

I Have Two Tables. TableA and TableB. In TableA each row have 4 fields :

1) DATETIME

2) X

3) Y

4) ID

in TableB  4 fileds too.

1)ID

2) START_TIME

3) END_TIME

4)CLIENT_ID

I need to select all rows from table A and Add to result rows 1 field TableB.CLIENT_ID

 

next rule must be used to pick CLIENT_ID for each TableA row :

SELECT CLIENT_ID FROM TableB WHERE TableA.DATETIME BETWEEN TableB.START_TIME and TableB.END_TIME

 

 

Is it possible to generate such query

thanks in advance

 

 

 

 



Answer this question

Help in Generate Specefic Sql Query

  • cropcircles

    Is it imposible

    or i'm give not full info


  • careywalker

    You need to join the two tables in a SELECT statement like:
     
    SELECT a.*, b.CLIENT_ID
    FROM TableA AS a
    JOIN TableB as b
    on a.DATETIME BETWEEN b.START_TIME and b.END_TIME
     
    Please see Books Online for more examples and syntax of the SELECT statement. You should also get a hold of a basic SQL book that will explain the SQL language with examples.


  • HiddenSphinx

    It is not clear exactly what you are trying to accomplish.  Are the table related If so, you can join the tables together through JOIN.  If you want the result set from one table to be joined to another table, then you might use a UNION. There are other types of queries that might work, but without more info, I can be more helpful.

    Peter



  • Help in Generate Specefic Sql Query