Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Handling NULL in existing project Expand / Collapse
Author
Message
Posted Monday, April 20, 2009 1:51 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, June 15, 2012 2:04 PM
Points: 29, Visits: 124
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
Post #700416
Posted Monday, April 20, 2009 6:19 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 1:09 PM
Points: 15,662, Visits: 28,053
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
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #700540
Posted Tuesday, April 21, 2009 4:03 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, June 15, 2012 2:04 PM
Points: 29, Visits: 124
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.
Post #701268
Posted Tuesday, April 21, 2009 6:24 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 1:09 PM
Points: 15,662, Visits: 28,053
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
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #701366
Posted Wednesday, April 22, 2009 7:43 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 1:55 AM
Points: 1,541, Visits: 8,208
Another option is the ISNULL function, which I use to remove NULL values from the output.


BrainDonor
Linkedin
Blog Site
Post #702338
Posted Friday, April 24, 2009 3:03 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Wednesday, August 13, 2014 9:41 AM
Points: 3,241, Visits: 4,999
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 here

Post #703799
Posted Tuesday, April 28, 2009 1:26 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, June 15, 2012 2:04 PM
Points: 29, Visits: 124
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.

Post #705550
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse