• It looks like that is a great candidate for converting to a table parameter. It would certainly make this a lot easier to maintain.

    CREATE TYPE VarChar8K as Table

    (

    Col1 varchar(8000) null

    )

    Then in your calling application you just need to populate your type instead on 192 variables. Your query is a lot simpler after that.

    exec sp_prepexec @p1 output,N'@P1 VarChar8K,@P193 varchar(8000),@P194 varchar(8000),@P195 varchar(8000)',

    N'SELECT ENTITY_ID, NM, FORMAT, INTEGRITY, TEXT, REFERENCE, ALG, LANG, COMP, CHARSET, PAR_ID, UPDTSEQ, CONF

    FROM w_entity_document_test_new n

    INNER JOIN @p1 p1 on n.ENTITY_ID = p1.Col1

    WHERE ENTITY_TYP_CD=@P193 AND DOC_TYP_CD = @P194 AND STS_CD = @p195

    You also have the advantage that if you want to have more or less values you either add them or don't add them to your table. You are no longer stuck with a fixed number of possibilities.

    As for the performance, the method I mentioned would be a huge difference in the query so if you go this route I would just get it working first and then evaluate the performance. It is likely that the indexing scheme would be somewhat different for this type of approach.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/