Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
hokiejonp
Starting Member
2 Posts |
Posted - 2010-02-26 : 13:32:53
|
Okay it seems so simple but somehow I have lost my SQL ammo...Help me out with this if you can please:I have two tables (for the sake of this question I will make ithorribly simple) and I want to return ALL data for a search on a datefor the corresponding table. (see picture: http://i.imgur.com/4QUNd.jpg)Ideally I want to submit one date and then return all of the rows for "Mike" if there is one row in common for the date on Table 2. So if I did a query on 5/5/10 I would want to get back Mike, 0.1, 5/5/10 AND 5/6/10 but I can only seem to get back the 5/5/10 row.I am basically searching on a query like this:SELECT Table1.*, Table2.*FROM Table1 INNER JOIN Table2 ON Table1.Key = Table2.KeyWHERE Table2.Date = '5/5/2010' ;Any ideas? It seems so easy... the files are... in the computer  |
|
Kristen
Test
22859 Posts |
Posted - 2010-02-26 : 14:05:03
|
[code]SELECT Table1.*, Table2.*FROM Table1 INNER JOIN Table2 ON Table1.Key = Table2.KeyWHERE Table2.Date = '5/5/2010' OR Table1.Name = 'Mike'[/code]Note that if you use "text string" dates they should be in the format '20100505' - yyyymmdd - which is locale-neutral and will not get mucked about by the various possible settings for SQL and Computer. |
 |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-02-26 : 14:13:52
|
Note that if you use "text string" dates they should be in the format '20100505' - yyyymmdd - which is locale-neutral and will not get mucked about by the various possible settings for SQL and Computer.careful...not true in ms access |
 |
|
Kristen
Test
22859 Posts |
Posted - 2010-02-26 : 15:21:08
|
Ah, sorry, thanks for pointing that out Russell. I had not spotted that I was replying in Access forum.All my advice was for SQL Server, so probably no use in Access. |
 |
|
hokiejonp
Starting Member
2 Posts |
Posted - 2010-02-26 : 16:27:52
|
Thank you guys... the date is passed by a form so the SQL checks out and returns data, it just returns only the one row from Table 2 where the date matches and ideally I want all rows that share the foreign key. I also want to rely only on the date variable to recover those rows.I feel like it would be a small change, but it may be a much more complicated SQL statement to capture those results. |
 |
|
Kristen
Test
22859 Posts |
Posted - 2010-02-27 : 00:09:47
|
Is this Microsoft Access or SQL Server? (You have posted this question in the MS Access forum) |
 |
|
|
|
|