Dynamically create a sql script only selecting columns where there is data

  • Morning,

    Thanks for your help in advance, very much appreciated.

    I have created some dynamic sql to check a temporary table that is created on the fly for any columns that do contain data. If they do the column name is added to a dynamic sql, if not they are excluded. This looks like:

    If (select sum(Case when [Sat] is null then 0 else 1 end) from #TABLE) >= 1 begin set @OIL_BULK = @OIL_BULK + '[Sat]' +',' END

    However, I am currently running this on over 230 columns and large tables 1.3 mil rows and it is quite slow. Does anyone have any ideas how I can dynamically create a sql script that only selects the columns in the table where there is data in a speedier manner. Unfortunately it has to be on the fly because the temporary table is created on the fly.

    Many Thanks for your help,

    Oliver

  • sorry firefox crashed when I added the post, sorry for double posting.

    PLEASE Remove this post.

    Very sorry

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply