Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Left outer join...

Status
Not open for further replies.
Apr 3, 2002
25
FR
Can you set a default value for the returned fields when using the left outer join? As it stands it will return a blank field, but I need a default value without having to change the table.
 
Is this what you are looking for. 0 will be appended to the output table. I hope it helps.


SELECT a.*, b.field, "0" AS newone
FROM Tbale1 AS a LEFT JOIN Table2 AS b ON a.field = b.field;
 
As you cannot edit the SELECT portion of the SQL statement in Crystal, the above wouldn't work. As well, the value for b.field would still be null, as appending another value to the result set wouldn't alter the value of b.field.

SELECT a.somefield, b.field
FROM Table1 AS a LEFT JOIN Table2 AS b ON a.field = b.field

Instead, create a formula in Crystal check for a null value, and replace the null value with your default.
//Assumes {b.field} is a string
If IsNull({b.field}) then 'default value
Else {b.field}

There are other ways to solve this, including the use of SQL Expressions, views, stored procs, but this formula based solution will work with any database driver. Malcolm Wynden
Authorized Crystal Engineer
malcolm@wynden.net
 
the simplest way is to convert nulls to a default value as a report option...but I would much better like to control this in a formula as Malcolm has shown
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top