Print Page | Close Window

SQL formula %test

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=22939
Printed Date: 01 May 2024 at 7:06pm


Topic: SQL formula %test
Posted By: elly00
Subject: SQL formula %test
Date Posted: 23 Jul 2021 at 2:59am
Hi

I'm using crystal sql formula syntax I need to set something like that..

if field1='' os field1 is null then
(
SELECT TOP 1 aaa
FROM my table

else
(
select TOP1 bbb
FROM my table 2
)

What is the correct syntax to use?


Thanks




Replies:
Posted By: kevlray
Date Posted: 26 Jul 2021 at 3:45am
I do not believe you can do that in a formula, but I think you would have to do in in a SQL Expression Field or a Command.  But the MS-SQL syntax would look something like this (I am assuming that field 1 is from another table).

SELECT CASE WHEN field1 IS NULL THEN (SELECT TOP 1 aaa FROM myTable ELSE
  (SELECT TOP 1 bbb from myTable2) END

FROM ANOTHERTABLE

FROM



Print Page | Close Window