×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

What is the equivalent in Interbase for Isnull in SQL server?

What is the equivalent in Interbase for Isnull in SQL server?

What is the equivalent in Interbase for Isnull in SQL server?

(OP)
Hi all

I think an example will explain my problem the best.

I have the following SQL select statement:

select (sum(sold) - sum(paid)) as duty
from clients
join sold on sold.client_id=clients.id
join paid on paid.client_id=clients.id
where clients.id=<whatever>

The obvous problem is that if a certain client never paid anything, sum(paid) returns null, so sum(sold)-sum(paid) returns null instead of sum(sold).

What I want is a function like NVL or ISNULL equivalent in Interbase or if someone knows a workaround to make my select return a 0 if the value is null. In SQL Server it would look as follows:

select (sum(sold) - isnull(sum(paid), 0)) as duty
from clients
join sold on sold.client_id=clients.id
join paid on paid.client_id=clients.id
where clients.id=<whatever>

Hope this makes sence and someone can help me out there.

Thank you everybody.

RE: What is the equivalent in Interbase for Isnull in SQL server?

This is not a complete solution, but you should be able to get an idea of a possible routine here...
============================================
SET TERM !! ;
CREATE PROCEDURE test_null
RETURNS (total NUMERIC(15, 2))
AS
DECLARE VARIABLE tot DECIMAL(12, 2);
BEGIN
tot = 0;
SELECT SUM(Test)
FROM test
INTO :tot;
IF (tot IS NULL) THEN
BEGIN
 Total = 0;
 SUSPEND;
END
ELSE
BEGIN
total = tot;
SUSPEND;
END
END;!!
============================================

Opp.


RE: What is the equivalent in Interbase for Isnull in SQL server?

Use UDF !
I test this in Delphi,that's working!

function udf_isnull(A:pchar;B:pchar):PChar;cdecl;
begin
  if strpas(A)='' then result:=B else result:=A;
end;

DECLARE EXTERNAL FUNCTION udf_isnull
CSTRING(256) CHARACTER SET NONE, CSTRING(256) CHARACTER SET NONE
RETURNS CSTRING(256) CHARACTER SET NONE FREE_IT
ENTRY_POINT 'udf_isnull' MODULE_NAME 'test.dll';

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close