if exist dynamic sql

  • my except query is like this

    @sqed = @pra_name +'EXCEPT'+@dea_name

    pre_name ; select * from table1

    dea_name : select * from table2

    I m doing exec sp_execute sql @sqed

    which gives me either rows or nothing in output.

    what I want is if it give me 0 rows I ndont need to display it as output.

    can I have

    insert into #temp table

    sp_executesql @sqed 

  • Not sure what you are asking, could be that it is late on Friday and I am looking forward to the weekend.

  • Try it.  That is the best way to know for sure.  Inserting into a temp table (as long as your tempdb isn't full, which will cause other problems as well) will succeed and you can drop it afterwards.

    The above is all just my opinion on what you should do. 
    As with all advice you find on a random internet forum - you shouldn't blindly follow it.  Always test on a test server to see if there is negative side effects before making changes to live!
    I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.

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

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