Does anyone know of a way to create a table definition from a stored procedure result set?
I have a stored procedure that creates a result set with 30 + columns, I would like to get this into a table without having to manually create all the columns of the table.
Is there a built-in procedure that will unload column names and types.?
Thank.
You can do this, but I donβt know if I recommend it:
EXEC sp_configure 'Show Advanced Options', 1 GO RECONFIGURE GO EXEC sp_configure 'Ad Hoc Distributed Queries', 1 GO RECONFIGURE GO SELECT * INTO #table FROM OPENROWSET( 'SQLNCLI', 'SERVER=.;Trusted_Connection=yes', 'EXEC StoredProcedureName' )
If this is one time, you can try it (not in production!).
, , INTO YourNewTable FROM. 1 , .
INTO YourNewTable
FROM
, YourNewTable SQl Server Management Studio , :
YourNewTable
SELECT * FROM INFORMATION_SCHEMA.Columns WHERE TABLE_NAME='YourNewTable' ORDER BY ORDINAL_POSITION
"SELECT INTO" "WHERE 1 = 0", .
:
if you want a NOT NULL constraint, then you should use in select: isnull (yourcolumn, '123') as your column, and then in where where put WHERE yourcolumn <> '123'
Source: https://habr.com/ru/post/1737686/More articles:Using admin panel with declarative authorization and autology? - ruby-on-railsWhy does my php base class expect an argument when I create it? - phpSet Android Watch List Size - androidSql Server 2000 Stored Procedure Preventing Parallelism or Something Else? - performanceThe type already contains a definition for 'Zehut' - c #using libcurl to check if a file exists on an SFTP site - c ++How to send non-fatal warnings from a library - language-agnosticSQL counts individual subnets in IP column - sqlhash password giving different results - c #https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1737691/write-set-of-integers-to-stdofstream-and-be-able-to-read-them-back&usg=ALkJrhgEy4i5KGeP_i-CDnjpOyAX-889uQAll Articles