• There are few things in this design which would make me to reject this solution completely:

    1. Use of xp_cmdshell

    2. Writing file out on SQL Server (or mapped dirve)

    3. Use of permanent table - until adding complexity, it has a risk of reporting crap if for some reason this process runs silmulteniously from mulitple sessions.

    I would stop this proc with populating #Results table and selecting * (or whatever required) from it.

    The caller process should be made responsible for persisting the results.

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]