locked
Optimizing TSQL query with CASE RRS feed

  • Question

  • User-2096461057 posted

    Hello, my application takes a long time when querying the database. In terms of optimization is it bteer to use

    (t.[description] = (CASE WHEN @selctDescription = '' THEN '%' ELSE @selctDescription END))

    or

    ((@selctDescription IS NULL OR @selctDescription = '') OR (t.[description] = @selctDescription))

    Thanks

    Tuesday, November 15, 2011 4:58 AM

Answers

  • User-784583665 posted

    second query is better In terms of optimization

    Please mark as answer if useful

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 15, 2011 5:03 AM

All replies

  • User-784583665 posted

    second query is better In terms of optimization

    Please mark as answer if useful

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 15, 2011 5:03 AM
  • User-2096461057 posted

    Thanks, may you provide some arguments as well thanks

    Tuesday, November 15, 2011 5:14 AM
  • User77042963 posted

    If you are using SQL Server 2008 and put your query in a stored procedure, you can recompile your query at the end of your query.

    OPTION (RECOMPILE)

    You can compare your query performance in SSMS and application to see whether they are running the same way or not. You can start from here.

    Tuesday, November 15, 2011 12:17 PM