Rx_
Nothing In Moderation
- Local time
- Yesterday, 21:44
- Joined
- Oct 22, 2009
- Messages
- 2,803
Is there an efficient way to return a -1/0 instead of some number/0?
A table has 4 outer joins to views that return a value or null depending on if that field represents a Federal lease.
These 4 outer joins work.
The result is a ID_Wells column and 4 columns with any combination of values or Null.
This line of TSQL:
ISNULL(ISNULL(dbo.vRE_FedLeaseType.Fed_Lease_Type, '')
+ ISNULL(dbo.vRE_FedLeaseMinOwn.MinOwn, '') + ISNULL(dbo.vRE_FedLeaseSurfOwn.SurfOwn, '') + ISNULL(dbo.vRE_FedDirHzLease.Expr1, ''), '') AS HasFedLease
This creates another final summary column [HasFedLease] that returns 0 or some number.
For the Rule Engine - 0 is False, any other number is True.
Acces links to this SQL View. Is there a quick way with out a UDF to convert numbers > 0 to a -1?
A table has 4 outer joins to views that return a value or null depending on if that field represents a Federal lease.
These 4 outer joins work.
The result is a ID_Wells column and 4 columns with any combination of values or Null.
This line of TSQL:
ISNULL(ISNULL(dbo.vRE_FedLeaseType.Fed_Lease_Type, '')
+ ISNULL(dbo.vRE_FedLeaseMinOwn.MinOwn, '') + ISNULL(dbo.vRE_FedLeaseSurfOwn.SurfOwn, '') + ISNULL(dbo.vRE_FedDirHzLease.Expr1, ''), '') AS HasFedLease
This creates another final summary column [HasFedLease] that returns 0 or some number.
For the Rule Engine - 0 is False, any other number is True.
Acces links to this SQL View. Is there a quick way with out a UDF to convert numbers > 0 to a -1?
Code:
SELECT dbo.Wells.ID_Wells, dbo.vRE_FedLeaseType.Fed_Lease_Type, dbo.vRE_FedLeaseMinOwn.MinOwn, dbo.vRE_FedLeaseSurfOwn.SurfOwn,
dbo.vRE_FedDirHzLease.Expr1 AS CountOffedLeaseDirHz, ISNULL(ISNULL(dbo.vRE_FedLeaseType.Fed_Lease_Type, '')
+ ISNULL(dbo.vRE_FedLeaseMinOwn.MinOwn, '') + ISNULL(dbo.vRE_FedLeaseSurfOwn.SurfOwn, '') + ISNULL(dbo.vRE_FedDirHzLease.Expr1, ''), '')
AS HasFedLease
FROM dbo.Wells LEFT OUTER JOIN
dbo.vRE_FedDirHzLease ON dbo.Wells.ID_Wells = dbo.vRE_FedDirHzLease.ID_Wells LEFT OUTER JOIN
dbo.vRE_FedLeaseSurfOwn ON dbo.Wells.ID_Wells = dbo.vRE_FedLeaseSurfOwn.ID_Wells LEFT OUTER JOIN
dbo.vRE_FedLeaseMinOwn ON dbo.Wells.ID_Wells = dbo.vRE_FedLeaseMinOwn.ID_Wells LEFT OUTER JOIN
dbo.vRE_FedLeaseType ON dbo.Wells.ID_Wells = dbo.vRE_FedLeaseType.ID_Wells