>>Hi,
>>
>>I have a situation where in the SQL Select, the JOIN should have a table (MyTable2) from another SQL Server database. Here is an example:
>>
>>local cJoinSqlServer
>>cJoinSqlServer = "SQL2Name.dbo."
>>cSqlSelect = "select * from mytable join " + cJoinSqlServer + "MyTable2 on MyTable.pk_field = MyTable2.pk_field"
>>
>>The above syntax works.
>>And then I tried to add the cJoinSqlServer to the ON part as follows:
>>
>>local cJoinSqlServer
>>cJoinSqlServer = "SQL2Name.dbo."
>>cSqlSelect = "select * from mytable join " + cJoinSqlServer + "MyTable2 on MyTable.pk_field = " + cJoinSqlServer + "MyTable2.pk_field"
>>
>>
>>The above works too; no error. But do I really need to add this prefix (of the second SQL Server DB) to the ON part?
>
>KISS and keep it clear IMHO, yours is not, whether you use the full dbname.schema.tablename or not:
>
>cJoinSqlDatabase = "SQL2Name.dbo."
>
>TEXT TO cSqlSelect TEXTMERGE NOSHOW PRETEXT 15
> Select t1.fieldName1, ..., t1.fieldNameN, t2.fieldName1, ..., t2.fieldNameN, t3.fieldName1, ..., t3.fieldNameN
> FROM myTable t1
> Join << m.cJoinSqlDatabase >>.MyTable2 t2 on t1.pk_field = t2.pk_field
> join << m.cJoinSqlDatabase >>.MyTable3 t3 on t2.pk_field = t3.pk_field
>ENDTEXT
>
>PS: Do not forget to rename fields which have the same name (ie: pk_field).
Now, I think I understand better what Dragan said too. That if I use the aliases then I don't have to use the cJoinSqlDatabase in the ON clause.
Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham