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 |
|
XjulieX
Starting Member
3 Posts |
Posted - 2005-02-01 : 14:55:23
|
| Hello, Thank you in advance for viewing this issue.I am new to SQL and am trying to modify a query that someone else has written. It appears the join used is 'outdated' according to a SQL video I have.The 'outdated' join statement works great:SELECT TblA.DateTime, TblB.DateTimeFROM Table_A TblA, (Select DateTime From Table_B Where DateTime > 'xx/xx/xx' and DateTime < 'xx/xx/xx' And ColumnA = X) TblBWHERE (TblA.DateTime > 'xx/xx/xx' and TblB.DateTime < 'xx/xx/xx') AND TblA.ColumnP = Y AND TblA.DateTime *= TblB.DateTimeORDER BY by TblA.Datetime I tried to 'update' the statement with the suggested 'left outer join' and 'on' clause:SELECT TblA.DateTime, TblB.DateTimeFROM Table_A TblA LEFT OUTER JOIN TblB ON TblA.DateTime = TblB.DateTime (Select DateTime From Table_B Where DateTime > 'xx/xx/xx' and DateTime < 'xx/xx/xx' And ColumnA = X) TblBWHERE (TblA.DateTime > 'xx/xx/xx' and TblB.DateTime < 'xx/xx/xx') AND TblA.ColumnP = YORDER BY by TblA.Datetime But I get the following error message:Server: Msg 156, Level 15, State 1, Line 4Incorrect syntax near the keyword 'Select'.Server: Msg 170, Level 15, State 1, Line 7Line 7: Incorrect syntax near ')'.Any tips or suggestions are greatly appreciated.Thank you!Julie |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-02-01 : 14:58:56
|
this should do it.read up on join syntax in BOL = Books Online = Sql helpSELECT TblA.DateTime, TblB.DateTimeFROM Table_A TblA LEFT JOIN (Select DateTime From Table_B Where DateTime > 'xx/xx/xx' and DateTime < 'xx/xx/xx' And ColumnA = X) TblB ON TblA.DateTime = TblB.DateTimeWHERE (TblA.DateTime > 'xx/xx/xx' and TblB.DateTime < 'xx/xx/xx') AND TblA.ColumnP = 'Y'ORDER BY TblA.Datetime Go with the flow & have fun! Else fight the flow |
 |
|
|
XjulieX
Starting Member
3 Posts |
Posted - 2005-02-01 : 16:01:47
|
quote: Originally posted by spirit1 this should do it.read up on join syntax in BOL = Books Online = Sql helpSELECT TblA.DateTime, TblB.DateTimeFROM Table_A TblA LEFT JOIN (Select DateTime From Table_B Where DateTime > 'xx/xx/xx' and DateTime < 'xx/xx/xx' And ColumnA = X) TblB ON TblA.DateTime = TblB.DateTimeWHERE (TblA.DateTime > 'xx/xx/xx' and TblB.DateTime < 'xx/xx/xx') AND TblA.ColumnP = 'Y'ORDER BY TblA.Datetime Go with the flow & have fun! Else fight the flow 
|
 |
|
|
XjulieX
Starting Member
3 Posts |
Posted - 2005-02-01 : 16:02:38
|
Looks like it works! Thank you!quote: Originally posted by spirit1 this should do it.read up on join syntax in BOL = Books Online = Sql helpSELECT TblA.DateTime, TblB.DateTimeFROM Table_A TblA LEFT JOIN (Select DateTime From Table_B Where DateTime > 'xx/xx/xx' and DateTime < 'xx/xx/xx' And ColumnA = X) TblB ON TblA.DateTime = TblB.DateTimeWHERE (TblA.DateTime > 'xx/xx/xx' and TblB.DateTime < 'xx/xx/xx') AND TblA.ColumnP = 'Y'ORDER BY TblA.Datetime Go with the flow & have fun! Else fight the flow 
|
 |
|
|
|
|
|
|
|