Expand * doesn't pickup all the columns from a Temp Table
BrienKing
Posts: 30 Bronze 3
If you have something like this:
SELECT
[a].Field1,
[a].Field2,
[b].AnotherField1,
[b].AnotherField2
INTO
#TempTable
FROM
TableA
LEFT OUTER JOIN TableB ON TableA.Field1 = TableB.AnotherField1
Then you add:
SELECT
tt.*
FROM
#TempTable tt
Then you put your cursor on the * and hit the Tab key you get:
SELECT
[tt].Field1,
[tt].Field2
FROM
#TempTable tt
None of the fields from Table B show up.
SELECT
[a].Field1,
[a].Field2,
[b].AnotherField1,
[b].AnotherField2
INTO
#TempTable
FROM
TableA
LEFT OUTER JOIN TableB ON TableA.Field1 = TableB.AnotherField1
Then you add:
SELECT
tt.*
FROM
#TempTable tt
Then you put your cursor on the * and hit the Tab key you get:
SELECT
[tt].Field1,
[tt].Field2
FROM
#TempTable tt
None of the fields from Table B show up.
Tagged:
Answers
I have just tested this scenario on SQL Prompt 9.5.14 (latest), on SSMS 17 and it worked correctly:
Product Support Engineer
Redgate Software Ltd
Please see our Help Center for detailed guides on how to use our tools
SELECT *, a+b as ab FROM #TempTable), CTE2 AS (
SELECT *, c+d as cd FROM CTE1)
SELECT * FROM CTE2
It becomes:
The other * columns from #TempTable aren't returned in the final output
Product Support Engineer
Redgate Software Ltd
Please see our Help Center for detailed guides on how to use our tools