Subquery issues in 3.5
PDinCA
Posts: 642 Silver 1
I had a working query:
I carried on typing the alias myself, followed by the start of my WHERE clause that uses an "ind" column. After the space following the "WHERE", as in:
As the alias is ignored, the candidate list after typing "ind." doesn't contain any columns from the Individual table - issue #2 "consequence"?
As my line of code ends with another subquery, it's no surprise that the alias is also missing after I typed:
Wishing to name the resulting column, I completed the ( SELECT.. ) and typed my " AS " whereupon a candidate list of table names is presented - issue #3. I wanted:
Aside from this, there are MANY improvements, especially in dealing with large scripts, that work great - THANKS!
SELECT sd.* , ios.* FROM dbo.ShipDetail sd INNER JOIN dbo.OrderDetail od ON od.OrderDetailID = sd.OrderDetailID INNER JOIN dbo.ImportOrderShipment ios ON ios.OrderID = od.OrderID AND sd.ParcelCode = ios.ParcelCode INNER JOIN dbo.Product p ON p.ProductID = od.ItemID AND p.SKU = ios.ProductID WHERE sd.ShipMethodID = dbo.ShipMethod_Unknown() ORDER BY 1but need to get the SiteID for each Order, so I started to type:
, ( SELECT ind.SiteID FROM dbo.Individualexpecting my predefined alias of "ind" to appear after SP3.5 auto-filled the "Individual" table name - no alias. That's issue #1.
I carried on typing the alias myself, followed by the start of my WHERE clause that uses an "ind" column. After the space following the "WHERE", as in:
, ( SELECT ind.SiteID FROM dbo.Individual ind WHEREthe candidate list includes all the aliases from the main query, but ignores the "ind" alias I just typed - that's issue #2.
As the alias is ignored, the candidate list after typing "ind." doesn't contain any columns from the Individual table - issue #2 "consequence"?
As my line of code ends with another subquery, it's no surprise that the alias is also missing after I typed:
, ( SELECT ind.SiteID FROM dbo.Individual ind WHERE ind.IndividualID = ( SELECT o.IndividualID FROM dbo.Orders
Wishing to name the resulting column, I completed the ( SELECT.. ) and typed my " AS " whereupon a candidate list of table names is presented - issue #3. I wanted:
, ( SELECT ind.SiteID FROM dbo.Individual ind WHERE ind.IndividualID = ( SELECT o.IndividualID FROM dbo.Orders o WHERE o.OrderID = sd.OrderID ) ) AS SiteID"AS" should be sensitive to its context - SELECT or FROM and show column names for SELECT "AS"s. It's debateable whether there's any meaningful candidate for assigning an alias to a subquery when using "AS" in the FROM...
Aside from this, there are MANY improvements, especially in dealing with large scripts, that work great - THANKS!
Jesus Christ: Lunatic, liar or Lord?
Decide wisely...
Decide wisely...
Comments
Thanks,
Bart
Principal Consultant
bartread.com Ltd
Decide wisely...
So, what you ended up with when you started typing your subquery was something like (note that I'm using ^ to indicate the caret position):
The issue is that you've got an unterminated opening parenthesis in the middle of your query. If you're adding SQL at the end of your query this is usually fine, and often works better than adding a closing parenthesis, but in this situation it completely foxes Prompt. It ends up looking like your inner SELECT statement has two FROM clauses which screws it up.
The way to fix it is to do the following:
Now you can start entering your subquery:
You should find that this aliases your table and you can use all the aliases defined in your outer query. I managed to replicate this using the following query on the AdventureWorks 2005 database:
Hope that helps.
Thanks,
Bart
Principal Consultant
bartread.com Ltd
I noticed your response to the post at http://www.red-gate.com/messageboard/viewtopic.php?t=5277 was that the problem is fixed. Is it fixed in this scenario too?
If I "Do Not Connect", I get another "Authentication Required" dialog after typing the " FROM dbo." - is that fixed too?
There's still a bug after this - the "ind" alias doesn't appear after the WHERE, but all the other aliases in the query do show up... Did you get the same bugs or are you using 3.5 "Friday" edition?
Decide wisely...
OK thanks, I'm not sure what else to suggest for now, but we'll keep looking into this.
Thanks,
Bart
Principal Consultant
bartread.com Ltd
Coding an INSERT INTO ... SELECT FROM ... where the FROM is a Table Variable and the last column in the SELECT list is a COUNT(*) from a child table, as in: AS you can see the "WHER" is not "WHERE" followed by the criteria. The "WHERE" doesn't show up in the candidates list - in fact the list is empty...
Decide wisely...
Referring to the "Authentication Required" issue, I just copied 2 COMMENT lines into an existing comment bounded by /* .. */, then typed a few words, ending with a period (for end of sentence), and was aked to Authenticate!
Original: Final: where the additional typing started after the "ID's".
Hope this helps isolate the issue...
Candidate List doesn't pop up when the dot after the "pr" alias before the "ORDER BY" is typed, as in:
Decide wisely...