Answered by:
create table on the fly with OUTPUT INTO, not allowed?

Question
-
We can do SELECT * INTO #TmpTbl FROM Tbl.
So I was thinking we can do something similar with OUTPUT, but it doesn't look like you can do that. All the examples I found do it where you first create the temp table or table variable and OUTPUT INTO it.
Am I correct that you can't create temp tables on the fly with OUTPUT INTO?
Thursday, September 13, 2012 2:53 PM
Answers
-
You're correct. The table must exist before can be used with OUTPUT INTO.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog- Proposed as answer by Roberson Ferreira _ Thursday, September 13, 2012 5:05 PM
- Marked as answer by D00linDalton Thursday, September 13, 2012 5:31 PM
Thursday, September 13, 2012 3:01 PM -
What is scenario where you are trying to use the OUTPUT clause?
Can you post a sample query?
BTW, you can create table on-the-fly, by adding an extra SELECT statement with "WHERE 1=2" clause before the query containing OUTPUT clause.
~manoj | email: http://scr.im/m22g
http://sqlwithmanoj.wordpress.com
MCCA 2011- Edited by Manoj Pandey (manub22)Microsoft employee Thursday, September 13, 2012 3:09 PM
- Marked as answer by D00linDalton Thursday, September 13, 2012 5:31 PM
Thursday, September 13, 2012 3:02 PM
All replies
-
You're correct. The table must exist before can be used with OUTPUT INTO.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog- Proposed as answer by Roberson Ferreira _ Thursday, September 13, 2012 5:05 PM
- Marked as answer by D00linDalton Thursday, September 13, 2012 5:31 PM
Thursday, September 13, 2012 3:01 PM -
What is scenario where you are trying to use the OUTPUT clause?
Can you post a sample query?
BTW, you can create table on-the-fly, by adding an extra SELECT statement with "WHERE 1=2" clause before the query containing OUTPUT clause.
~manoj | email: http://scr.im/m22g
http://sqlwithmanoj.wordpress.com
MCCA 2011- Edited by Manoj Pandey (manub22)Microsoft employee Thursday, September 13, 2012 3:09 PM
- Marked as answer by D00linDalton Thursday, September 13, 2012 5:31 PM
Thursday, September 13, 2012 3:02 PM -
OK, thanks Naomi for verifying my initial finding.
And manub, I understand what you are suggesting. I am just trying to avoid manaully creating that table. But like you said, I can run a select * into where 1=2 to create the empty table before I do the sql where I want to use OUTPUT.
Thursday, September 13, 2012 4:12 PM -
Check your scenario you can use Merge:
1) http://www.robersonferreira.com.br/merge_parte1/
2) http://www.robersonferreira.com.br/merge_parte2/
3) http://www.robersonferreira.com.br/merge_parte3/
Roberson Ferreira - Database Developer
Acesse: www.robersonferreira.com.br
Email: contato@robersonferreira.com.brSe esta sugestão for útil, por favor, classifique-a como útil.
Se ela lhe ajudar a resolver o problema, por favor, marque-a como Resposta.Thursday, September 13, 2012 5:10 PM