SQL Command/SQL Expression Fields

CR XI R2
Hi All,
Here's the situation.
There is an SQL table of lookup codes.  The columns in the table are "FIELD", "VALUE", and "DESCR".
The data looks like
CRA_TYPE      RV     Receiving
CRA_TYPE      AJ      Adjustment
CUST_TYPE    MD     Medical
CUST_TYPE    RT      Retail
The main datatables contain a "VALUE" in a particluar "FIELD" and I need to be able to retrieve the appropriate "DESCR" to output on the report.
There is a stored procedure that takes 'FIELD" and "VALUE" and selects "DESCR" but I can't figure out how to set it up as a formula field and pass parameters to it for each line.
It is basically
SELECT DESCR FROM tbLookUp WERE [FIELD]=@FIELD AND [VALUE]=@VALUE
The "FIELD" parameter would be static (in this case "CRA_TYPE") and the "VALUE" parameter would be the value of the CRA_TYPE field in each datarow.
I can't just use the "VALUE" since more than one field might have the same "VALUE" but a different "DESC".  Only the combination of "FIELD" and "VALUE" is unique.
I've been playing with SQL Commands and SQL Expression Fields with no success.  There aren't a lot of samples to look at especially the SQL Expression Fields.
I could create a new stored procedure that would just send in the translation but I don't want to create a stored procedure for every report and almost all the reports will need a similiar transaction scenario.
Any help would be greatly appreciated.  
Thanks in advance.
Larry

Yes, I am pretty familiar with Crystal, at least in the routine stuff and pretty good in VB and SQL.
In normal SQL I would retrieve it with a join to the LookupTable.
like: JOIN tbLookUp ON tbLookUp.FIELD = 'CRA_TYPE' AND ( tbLookUp.[value] = tbCRA.CRA_TYPE)
and then just add to the SELECT statement:   tbLookUp.DESCR
However, I can't find anyway to use the Database Expert to add the FIELD='CRA_TYPE" to the linking process
I was hoping the "SQL Expression Fields" might hold the answer but the documentation and examples on their use is pretty slim.
I was hoping for a way to run something like:  SELECT DESCR FROM tbLookUp WHERE FIELD = 'CRA_TYPE' AND [value] = {tbCR_AUDIT.CRA_TYPE} which would evaluatefor each record like a Formula Field which I could then just insert into the report.
Everything I've tried in the formula editor for an SQL Expression is no good, but run just fine in the SQL Server Management Studio.
I could just skip the "Database Expert" completly and write an SQL Expression as a "SQL Command" that would retrieve it but I'm trying to use the "Database Expert" for ease of maintenance by other people later on and keep as much as I can in CR.
Maybe I'm asking CR for too much.
Thanks

Similar Messages

  • SQL Expression Fields button not visible in Field Explorer

    Hi,
    On my Crystal Reports installation I can see the button SQL Expression Fields in Field Explorer but it is not visible on client's installation.
    How do I make it visible? I need to create a new report with SQL query for client.
    Thanks,
    Ajay Audich

    Commands are intended to replace the standard linked tables that must users are accustomed to.
    I suppose Commands would be considered an "advanced" feature, considering that they require the developer to be able to hand write SQL (our at least copy it from another SQL editor).
    If you are comfortable writing reading, writing & editing SQL, Commands will open a the door to a whole new level of control when it comes to creating your data sets.
    The biggest problem w Commands is also it's greatest strength... If you're using a Command, CR will assume that you know what you're doing and will not try to rewrite or optimize your SQL in the background. You write it, CR sends it. That means if you write crappy SQL, CR will send your crappy SQL to the db server...
    It also means that you can use join types that aren't available in CR and use sub-queries in in your SQL... Basically anything you can do in the db's native editor.
    HTH,
    Jason

  • SQL Expression Fields

    In crystal report 2008,I create a SQL Expression Fields,but how to write the SQL query in the formula workshop,
    Edited by: nylethx1 ye on Jul 23, 2008 9:48 AM

    Select count(*) from Table
    Your query must return a unique value.
    From Don: SQL Expressions were not designed to run SELECT statements. Use a Command object for selects.
    Edited by: Don Williams on Nov 2, 2009 9:29 AM

  • Select statements inside a SQL Expression field

    Hello
    Why cannot we use the Select statements inside a SQL expression field in Crystal Reports ?
    Any alternatives for this...
    SELECT Top(1) "SomePrivateDatabase"."SPDname" FROM "SomePrivateDatabase"
    inner join "Subscriber" on
    "Subscriber"."SPDID" = "SomePrivateDatabase"."SPDID"
    inner join "UserDetails" on
    "UserDetails"."SPDID" = "SubscriberCore"."SPDID"
    Regards
    Srivatsa
    Edited by: Srivatsa Haridas on Dec 3, 2008 12:17 PM

    Hi Srivatsa,
    SQL Expressions is something the Database supports. We query the Client engine for a list of functions they make available. If the SQL Statement is not list it's not an option and therefore it won't work.
    Your work arounds are to use either a Stored Procedure, this is the most efficient way, all processing is done server side and CR simply waits for the data to format in the report. Another option is to use a
    Command Object, use one CO per report so try to get all data within the SQL statement. We simply pass the SQL to the server and wait for the result set, if you get an error it will be the SQL you typed in. Test in a SQL test tool first to confirm you are getting the data correctly.
    For more assistance in designing reports please post your report deisgn questions to the Reprot Design forums. I am moving this one to that queue.
    Thank you
    Don

  • SQL Expression Fields (Field Explorer dialog box)

    I have Crystal Reports Version XI.  When I open the field explorer I can't see "SQL Expression Fields (Field Explorer dialog box) "
    Please help.

    The following information helps you
    Symptom
    In Crystal Reports 9 and later, the 'SQL Expression Fields' is unavailable in the 'Field Explorer' dialog box. The report is reporting off a stored procedure or command object.
    Why are 'SQL Expression Fields' unavailable in the 'Field Explorer' dialog box?
    Resolution
    'SQL Expression Fields' are unavailable in the 'Field Explorer' dialog box because the report is based on a stored procedure or command object.
    When connecting to a Stored Procedure or using a command object the SQL Statement is predefined and cannot be modified by Crystal Reports therefore the SQL Expression field will not be available when connecting to either of these objects.
    The SQL Expression field works by adding an entry into the SELECT portion of the SQL Statement in a Crystal report. A SQL Expression Field is only available in a report when:
    u2022 The report connects to tables or views.
    u2022 Crystal Reports generates the SQL statement.
    regards,
    Raghavendra

  • Sql expressions field disappears

    I updated to CR XI Release 2 and the sql expressions field disappeared. It is there only in subreports. What is wrong?
    Thanks in advance

    Hi Kiril
    Let me know if you are using any stored procedure in the main report or not?
    If you are using any stored procedure or command object in the report then the SQL expresions is not available in Crystal Reports.
    There is an SAP note on SAP Developer network addressing this issue.
    You first need to logon to https://www.sdn.sap.com
    and search for:
    1217791 - 'SQL Expression Fields' are unavailable in the CR Field Explorer
    let me know if it helps or not.
    Regards
    Nikhil

  • Cannot find SQL Expression Fields

    Hi,
    I am using Crystal Reports 2008 and trying to locate the SQL Expression Fields.  According to the user guide, the SQL Expresion Fields should be under Field Explorer.  But when I go to Field Explorer, I only see the following options:
    - Database Fields
    - Formula Fields
    - Parameter Fields
    - Running Total Fields
    - Group Name Fields
    - Special Fields
    Would you please let me know where I can find SQL Expression Fields?
    Thanks and regards,
    Al

    Al,
    If you are reporting off of a Stored Procedure, View, Command Object, or multiple datasources SQL Expression fields will not be available. The reason is for the first 3 is that the SQL has been hard coded, the reason it would not work when ussing multiple datasources is that it would not know which query to append the SQL expression to.
    Correction: SQL Expressions will be available when reporting off of a View.
    Edited by: Graham Cunningham on Jul 21, 2008 9:38 AM

  • NOT ABLE TO SEE SQL EXPRESSION FIELDS IN CR2008

    Hi,
    I am not able to see the SQL EXPRESSION FIELDS in the FIELD EXPLORER of CR 2008.Can
    you please help me
    BABASHARI

    Hi,
    I would suggest you open the question in the Crystal Reports forum.
    Ingo

  • SQL Expression fields do not display when no records are returned

    I have a report that uses SQl expression fields to summarize in the Report footer.  When the main report does not contain any records the SQL expression fields are blank.
    Is there a way to force these SQL expression fields to be evaluated evn when the main report does not contain any records.
    Thanks

    Hi,
    You can try this :
    Under Report Options, check "Convert Database Null values to Default".

  • Passing a variable to an SQL Expression Field

    Is it possible to pass a value or variable to an SQL Epression field?  I want to sum the values of open invoices for a particulat customer and want to do this using an SQL Expression Field.  I need this sum in a  subreport and since I can not put a subreport in a subreport I want to do it using an SQL Expression.
    Thanks.
    Ralph

    That would require a SELECT statement in the expression and they really are not designed to do that.
    If you can't do this client side write a stored procedure then you have full control and CR is just used to display the data.

  • Select Expert or SQL Expression Fields help

    I am trying to do something I would consider very simple but can figure it out.
    I have two tables.  FDC_Trips & Facility.  On the report I can get the FDC_Trips.DivertedbyFacility field to populate a number value because that field is an integer.  But we need the name to show up.  That field is the ID (foreign key) of a Facilty which matches with the field Facility.Code.  Instead of it displaying the DivertedbyFacility number/ID I would like it to be able to show the Facility.Name value.  If I place the filed Facility.Name field on my report it is blank. 
    How can I write a where clause to query the Name of the Facility where the Facility.Code = FDC_Trips.DivertedbyFacility?
    Do I use the Select Expert or SQL Expression Fields.
    Please advise.

    Actually you'll use the Links tab in the Database Expert. If CR did it's stupid auto linking thing... delete them. It usually get's it wrong.
    Now just link the fk field in FDC_Trips to the pk field in Facility. Once you have that done you'll be able to simply drop Facility.FacilityName directly onto the report.
    HTH,
    Jason

  • Sql expression fields in subreports (CR XI)

    Post Author: yyu
    CA Forum: Data Connectivity and SQL
    Is it normal that the sql expression fields don't show up in a subreport?
    I don't see any. Does anyone know how? Thanks!

    Sorry for the delay getting back to you all.
    I set up a report against the xtreme database sample. Added the Customer table, and put the columns "Customer ID" and "Customer Name" on the report. I then created a new SQL Expression and entered the following:
    ( SELECT SUM(`Orders`.`Order Amount`) FROM `Orders`
      WHERE `Orders`.`Customer ID`=`Customer`.`Customer ID`)
    I could save the new SQL Expression, which is farther than I got in the real report. I added the SQL Expression field to the report. But when I try to preview the report, I get an error:
    Error in compiling SQL Expression :
    Failed to open a rowset.
    Details: ADO Error Code: 0x800004005
    Source: Microsoft JET Database Engine
    Description: Unspecified Error
    Native Error: 62411
    I suspect that's the MS Access version of the error I was getting with MySQL.

  • SQL Expression Fields - Not available

    Post Author: anandad
    CA Forum: Data Connectivity and SQL
    Hi,
    I have installed Crystal Reports XI Developer version but in my Field Explorer I dont see SQL Expression Fields tab or item. Did I miss installing any perticular component? I can see the formulla fields but not SQL Expression Fields....
    Urgent help will be highly appritiated.
    Thanks.

    Post Author: synapsevampire
    CA Forum: Data Connectivity and SQL
    V361 is mistaken, SQL Expression fields are available in CRXI.
    As with previous versions though, it turns off depending upon the type of database and connectivity used.
    Try using a real SQL database, or if MS Access, set up an ODBC connection to the database.
    In the future include your database in your post to avoid guess work on our part.
    -k

  • SQL expression field is not displayed on the page header if no records

    Hello
    I'm creating a quite simple report. In this report I've got a SQL expression field which returns a DateTime
    I display this field on the page header section.
    Everything is working fine except when my principal query doesn't return any records my SQL expression field is not displayed. It doesn't seem to be evaluated.
    So, I would display this field even if my Details Section doesn't contains any record.
    I hope you understand what I mean.
    Can someone help me?
    thanks

    Hello,
    I thought about creating a formula but the value I need is stored in a database.
    So i created a simple SQL expression field.
    SELECT CONVERT(DATE,j_1) FROM VW_STD_DATEFIXING
    And this expression doesn't have any dependencies.

  • SQL Expression Field Help

    Need to create a SQL Expression Field based on this query - or can someone tell me how to do it CR syntax?
    SELECT Count("ordhdr"."ACCT_NO")
    FROM ordhdr
    WHERE (dt_in between '2011-01-01 and '2011-10-31')

    create a group, group off of account number.
    Your select statement should be close to this.
    in Date (2011, 01, 01) to Date (2011, 10, 31)
    You can drop your fields into the detail section.
    Right click the ordhrd select insert summary, group 1, and change it from sum to count.
    You can suppress the details.
    The corresponding SQL would look something like this.
    SELECT `ordhdr`, `acct_no`, `DT`
    FROM   `Datasource name`
    WHERE  (`DT`>=#2011-01-01 00:00:00# AND DT`<#2011-10-31 00:00:01#)
    ORDER BY `acct_no`

Maybe you are looking for

  • Officejet Pro 8500 Wireless - New toner cartridge is not working

    My brand new expensive HP original cyan cartridge is not printing. Although it now shows full on the screen and has ink at the opening of the cartridge, not a drop of cyan on test pages even after cleaning print heads and realigning. This is the 2nd

  • Macbook freezes a lot while watching video on safari?

    Hello everyone, I have a early 2007 black macbook, 2GHz, 2GB RAM dual core. I had OS X 10.4 before on my machine. So the story goes like this: once I had a little issue with ethernet cable and I went to apple store to correct it. They replaced my mot

  • NOkia 101 rm 769 brought to canada not working wit...

    Hi, When I was in Asia, i got a Nokia 101 RM 769. I took it with me to Canada to replace my stolen Nokia, but it is not working with my provider's SIM card (CHATR). How come?? What should I do? There is not information on the website, no way to talk

  • Using iDisk for the Autosave Vault?

    I'm currently using FCE with a MacBook Pro. I often use MacBook Pro hooked to a variety of external hard drives. However, sometime it would be nice to use it not hooked up to all of those drives. But I would still want to be able to have Autosave Vau

  • Struts-InfoView.xml file

    I'm currently running XIR2SP3 on a Windows server, Tomcat 5.0.27.  My Performance Mgmt link thru Infoview was working fine up until today when I received this error in the Tomcat logs: Parse Error at line 2 column 16: Document root element "struts-co