question

QHarris avatar image
QHarris asked

Insert result of EXEC sp_executesql into a temp table

Hi, I am attempting to return the names of all the columns, of datatype float, in a table that contain 1 one more nulls. First thoughts were to use a dynamic SQL script to select all columns in a table that have datatype float, insert the resultset into a temp table and search for nulls within this table. I have written the script that returns the columns that are of datatype float but am unsure how to insert the resultset into a temp table. As the column headers to be returned are unknown i cannot create a table in advance and then reference this table with INSERT INTO inside of the dynamic sql string. I have the following code line EXEC sp_executesql @SQLString, N'@Columns NVARCHAR(MAX) OUT',@COLUMNS OUT; This produces the output i would like to put into the table to then search for nulls in. The other way i thought about it, was to return only the column names in a table where the column has at least one null. Again, i haven't found a way to do this that returns only the column names where a null is present in any row. I have seen Aaron Betrand's answer to similar problem at the following link: http://dba.stackexchange.com/questions/14864/test-if-any-fields-are-null It doesn't, however, only return the column headers where a null is present in the rows beneath. Same issue with the xml solution here: http://dba.stackexchange.com/questions/14864/test-if-any-fields-are-null I am running Microsoft SQL Server 2008 R2 (SP2) Enterprise Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1) I would appreciate any pointers on how to do this please? Regards, Quentin
xmlnullinsert-exec-sql
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

· Write an Answer

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.