Using formula editor if statement RRS feed

  • Question

  • User-1210839387 posted

    using vs.net 2005/Sql server.

    I have 2 character fields that I am pulling from a db table which I call (names and possible values):

    isCondition:  Y or N

    dateStored:  (date)

    I want to write something like this in the WHERE part of the Formula editor


    If isCondition = "Y" Then



         dateStored = ""

    End If


    the main thing is I want to figure out how to display or hide the field based on the isCondition field.  thanks


    Friday, November 5, 2010 8:54 AM

All replies

  • User1801871119 posted

    what control you are using to display your data?

    posting your code will be very helpful.

    Friday, November 5, 2010 9:13 AM
  • User1224194097 posted

    Keep a TextObject and write this formula for Text property.

    If isCondition = "Y" Then




    End If

    You can do this in sql itself

    SELECT CASE WHEN IsCondition=1 THEN DateColumn
                       ELSE "" END DateColumn

    Try those and see if it works.

    Friday, November 5, 2010 9:16 AM
  • User-1210839387 posted

    thanks Sansan,

    that is what I want but I am new to crystal reports.

    when I go to "formula editor" I only see what looks like the "WHERE" clause of the sql statement. how do I see the "SELECT" part of the query so I can code the "SELECT CASE..." query that you mention?



    Friday, November 5, 2010 9:20 AM
  • User-1210839387 posted

    hi, i am using a crystal report.  I need to modify the query that returns the data.

    Friday, November 5, 2010 9:39 AM
  • User1224194097 posted

    There are two ways to do it. I am assuming that a stored procedure is the datasource for the report. 

    Method I:

    use CASE WHEN THEN.... in the SELECT Query that you write in the procedure.

    Method II:

    Drag a TextObject onto the desired report section, details of report header etc., and go to textobject projects and write formula for Text by clicking the little icon to the right.

    Friday, November 5, 2010 9:42 AM
  • User-1210839387 posted

    Hi Sansan,

    I realize that using a stored proc would be better.

    Right now I have an ODBC connection created in the crystal report and I am using (from top toolbar): Crystal Reports -> Database -> Database Expert

    anyways, how do i set a stored procedure as the datasource for my report.

    I have an odbc connection setup through database expert would I be able to add the stored procedure there?

    Friday, November 5, 2010 9:56 AM