Handling NULL in existing project

  • Hi,

    I have moved recently to a project, which is running fine in production for last 3 yrs.

    now when i am handling the performance issues, i have observed that there are lot code in vb.net files and lot code in script i.e. in stored procedures. most of the columns are defined as allow nulls, due to lack of proper requirement/coding, now there is lot of data with NULLs

    to handle these nulls in the script(sp), written case statements.

    So could any one help me out now, what is the better way to tune this issues, from the vb.net code and script of the stored procedures.

    Thanks

  • I'm not sure I understand the question. Are you trying to tune queries where there is a lot NULL columns?

    If so, yes, this can be an issue in 2005 and prior version because NULL values and indexes don't mix will to arrive a selective indexes. SQL Server 2008 has a filtered index that could help you here.

    If that's not the kind of information you're looking for, please clarify your concerns. Thanks.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thanks for your reply,

    Yeah as you mentioned i have read some article on 2005 , as this is an issue for indexing & Null .

    But my major problem is there is huge data i have with NULLs, now i want to tune the queries, such that the query should handle the nulls before sending the result back to UI. Right now i am achieving this by writing the "case" statement for each field like this.

    Case when Column1 is NULL then ''

    when Column1 is NOT NULL then Column1 end

    like this the script is written for all the columns in each table. Which i causing script to increase in 100's lines and also getting difficult to edit/fix any issues

    Can any one provide better way to handle this.

  • I wouldn't recommend using this method in the WHERE or JOIN clauses of your queries, but for the SELECT list, instead of CASE statements, try this:

    SELECT COALESCE(MyColumn,'') AS MyColumn

    ...

    That will do what you're trying to do with a lot less overhead.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Another option is the ISNULL function, which I use to remove NULL values from the output.

  • Its much better to set Default Values for such columns where NULLs can be inserted. This resolves many conversion issues.

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Sometimes, winning is not an issue but trying.
    You can check my BLOG
    [font="Arial Black"]here[/font][/url][/right]

  • YEAH,

    Exactly i was thinking in the same way, using the default values.

    I am just waiting for the default values for those fields from client.

    Thanks every one for your responses.

Viewing 7 posts - 1 through 6 (of 6 total)

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