views:

98

answers:

1

I'm currently migrating a customers application from ColdFusion on Windows with SQL Server to ColdFusion on Linux with MySQL and I'm running into some issues recreating their views with regards to joins.

Can anyone help me work out how the following should be converted.

SELECT 
<columns> 
FROM assetType 
INNER JOIN assets
INNER JOIN AssetToContent ON assets.asset_id = AssetToContent.asset_id 
ON assetType.asset_typeID = assets.asset_typeID 
RIGHT OUTER JOIN ContentType 
INNER JOIN Content ON ContentType.ContentTypeID = Content.ContentTypeID 
ON AssetToContent.ContentID = Content.ContentID 
LEFT OUTER JOIN Page_Content ON Content.ContentID = Page_Content.ContentID 
RIGHT OUTER JOIN Page ON Page_Content.PID = Page.PID 

The INNER JOIN's without an ON clause are what are tripping me up and I can't find any good SQL Server docs on the ordering of nested joins.

+3  A: 

This should work. I don't know what voodoo syntax SQL Server uses, but your ON clauses were all over the place:

SELECT 
<columns> 
FROM assetType 
INNER JOIN assets ON assetType.asset_typeID = assets.asset_typeID 
INNER JOIN AssetToContent ON assets.asset_id = AssetToContent.asset_id 
INNER JOIN Content ON AssetToContent.ContentID = Content.ContentID 
RIGHT OUTER JOIN ContentType ON ContentType.ContentTypeID = Content.ContentTypeID 
LEFT OUTER JOIN Page_Content ON Content.ContentID = Page_Content.ContentID 
RIGHT OUTER JOIN Page ON Page_Content.PID = Page.PID 
hobodave
Not sure why this was downvoted. It's syntactically valid MySQL and pairs up the ON clauses with the appropriate JOIN in the only way it makes sense to.
hobodave
SQL Server syntax is no more Voodoo than any other SQL dialect... especially when looking at what MySQL lets through as valid. ;) +1 for putting the joins straight.
Tomalak
The strange placement of the on clauses was not required by SQL Server, I suspect Cold Fusion just created the query in a non-standrd way. It was valid because the ON clauses were there, but people would not normally separate them when they manually write a query.
HLGEM
@HLGEM: Coldfusion does not (to my knowledge) create queries for you.
Tomalak