dbTalk Databases Forums  

IFNULL SQL function?

sybase.public.sqlanywhere.ultralite sybase.public.sqlanywhere.ultralite


Discuss IFNULL SQL function? in the sybase.public.sqlanywhere.ultralite forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
mct79c
 
Posts: n/a

Default IFNULL SQL function? - 01-08-2009 , 04:10 PM






I'm using UltraLite 9.0.2 and Visual Studio 2005 VB.NET.

Is it more efficient to use the IFNULL SQL function or check
for the Nothing value as shown below?

Option A:
Using cmd As New ULCommand("select
ifnull(DESCRIPTION , '',DESCRIPTION) as DESCRIPTION from
PARTS", _conn)
cursor = cmd.ExecuteReader
While cursor.MoveNext
txtComment.Text =
cursor.GetString(cursor.Schema.GetColumnID("DESCRI PTION"))

Option B:
Using cmd As New ULCommand("select DESCRIPTION
from PARTS", _conn)
cursor = cmd.ExecuteReader
While cursor.MoveNext
If Not
cursor.GetString(cursor.Schema.GetColumnID("DESCRI PTION")) =
Nothing Then
txtComment.Text =
cursor.GetString(cursor.Schema.GetColumnID("DESCRI PTION"))
Else
txtComment.Text = ""
End If

Thank you in advance.

Reply With Quote
  #2  
Old   
Paul Horan[Sybase]
 
Posts: n/a

Default Re: IFNULL SQL function? - 01-08-2009 , 09:44 PM






IIRC, IfNull() is not ANSI standard - it's a SQLAnywhere extension to the
SQL dialect.

I'd use:
select coalesce(DESCRIPTION , '') as DESCRIPTION
from PARTS


--
Paul Horan[Sybase]
paulhoran.pbdjmagazine.com

<mct79c> wrote

Quote:
I'm using UltraLite 9.0.2 and Visual Studio 2005 VB.NET.

Is it more efficient to use the IFNULL SQL function or check
for the Nothing value as shown below?

Option A:
Using cmd As New ULCommand("select
ifnull(DESCRIPTION , '',DESCRIPTION) as DESCRIPTION from
PARTS", _conn)
cursor = cmd.ExecuteReader
While cursor.MoveNext
txtComment.Text =
cursor.GetString(cursor.Schema.GetColumnID("DESCRI PTION"))

Option B:
Using cmd As New ULCommand("select DESCRIPTION
from PARTS", _conn)
cursor = cmd.ExecuteReader
While cursor.MoveNext
If Not
cursor.GetString(cursor.Schema.GetColumnID("DESCRI PTION")) =
Nothing Then
txtComment.Text =
cursor.GetString(cursor.Schema.GetColumnID("DESCRI PTION"))
Else
txtComment.Text = ""
End If

Thank you in advance.



Reply With Quote
  #3  
Old   
Breck Carter [TeamSybase]
 
Posts: n/a

Default Re: IFNULL SQL function? - 01-12-2009 , 07:25 AM



I'm guessing Option A will be better, but that you might not be able
to measure the difference.

Option A is a scalar SQL operation meaning that it doesn't involve any
extra manipulation of result sets. Plus, I would guess the low level
code inside UltraLite is faster than application code executing at the
very high VB level.

Plus, IMO, Option A is quite a bit simpler... that's a bigger reason
to use it.

Like Paul, I too prefer COALESCE... it is simpler to code as well.

Breck


On 8 Jan 2009 14:10:50 -0800, mct79c wrote:

Quote:
I'm using UltraLite 9.0.2 and Visual Studio 2005 VB.NET.

Is it more efficient to use the IFNULL SQL function or check
for the Nothing value as shown below?

Option A:
Using cmd As New ULCommand("select
ifnull(DESCRIPTION , '',DESCRIPTION) as DESCRIPTION from
PARTS", _conn)
cursor = cmd.ExecuteReader
While cursor.MoveNext
txtComment.Text =
cursor.GetString(cursor.Schema.GetColumnID("DESCRI PTION"))

Option B:
Using cmd As New ULCommand("select DESCRIPTION
from PARTS", _conn)
cursor = cmd.ExecuteReader
While cursor.MoveNext
If Not
cursor.GetString(cursor.Schema.GetColumnID("DESCRI PTION")) =
Nothing Then
txtComment.Text =
cursor.GetString(cursor.Schema.GetColumnID("DESCRI PTION"))
Else
txtComment.Text = ""
End If

Thank you in advance.
--
Breck Carter http://sqlanywhere.blogspot.com/

RisingRoad SQL Anywhere and MobiLink Professional Services
breck.carter (AT) risingroad (DOT) com


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.