[ACCEPTED]-Declare a table variable without column definitions?-sql-server-2000
Accepted answer
Impossible. Citation from "books online":
==============
Syntax Note 7 Use DECLARE @local_variable to declare 6 variables of type table.
table_type_definition ::=
TABLE ( { column_definition | table_constraint } [ ,...n ] )
==============
"(", at 5 least one column definition and ")" is syntactically 4 required.
PS: AFAIK insertion into any new 3 table from "exec" results are impossible 2 at all. Only to a table with predefined 1 structre.
You can't do it with table VARIABLES but 1 you can do it with TEMP tables.
-- Drop the table, if it exists
IF OBJECT_ID(N'tempdb.dbo.#tmpMyTable',N'U') IS NOT NULL
DROP TABLE #tmpMyTable
SELECT
ColumnA,
ColumnB
INTO #tmpMyTable
FROM MyTable
-- Then clean up after yourself
DROP TABLE #tmpMyTable
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.