Store the variable names in a database

Salvation;

I am storing calculations in a table of data and the need to recover them and run them in a query, one of them needs to access the value of an argument passed to the function to run the query/calculation. Problem is that I'm not sure how evaluate the variable when it is retrieved - it is not treating.

Any ideas?

Here's the function:

<cffunction
 name="fnShowliveSurcharge" access="public" output="true" 
returntype="any" hint="makes a calculation based on a formulae" >

        <cfargument name="avgCost" required="true" />

    

        <cfquery name="qryGetAlloys" datasource="#variables.dsn#" result="qryGetAlloys_results" >

            select * from nas_alloys;

        </cfquery>

        

        <cfquery name="qryGetGrades" datasource="#variables.dsn#" result="qryGetGrades_results" >

            select * from nas_grades order by id;

        </cfquery>

        

        <cfloop query="qryGetGrades">

            <cfloop query="qryGetAlloys">

                <cfquery name="qryGetSurcharge" datasource="#variables.dsn#" result="qryGetSurcharge_results">    

                    select 

                        #qryGetAlloys.formulae# as myValue

                    from nas_alloys a left join nas_triggers t on t.alloyid = a.id

                    left join nas_astm astm on astm.alloyid = a.id

                    left join nas_estimatedprice ep on ep.alloyid = a.id

                    where astm.gradeid = '#qryGetGrades.Id#'

                    and a.id = '#qryGetAlloys.Id#';

                </cfquery>

            </cfloop>

        </cfloop>

        

    </cffunction>

the second line of the query is the insertion

((#arguments.avgCost#-t.value) * (astm.astm/100) * 1.2)

the nas_alloys table, however the query ends up looking like;

Select ((#arguments.avgCost#-t.value) * (astm.astm/100) * 1.2) as myValue nas_alloys a left join nas_triggers t on t.alloyid = a.id left join nas_astm on astm.alloyid astm = a.id left join nas_estimatedprice ep on ep.alloyid = a.id where astm.gradeid = '1' and a.id = '1';

Instead of:

Select ((2.2289-t.value) * (astm.astm/100) * 1.2) as myValue nas_alloys a left join nas_triggers t on t.alloyid = a.id left join nas_astm on astm.alloyid astm = a.id left join nas_estimatedprice ep on ep.alloyid = a.id where astm.gradeid = '1' and a.id = '1';

Any thoughts on how to solve this problem?

-Thank you

-sean

Conditional logic is possible in sql in various ways.  One way that works with anything is a case construction.

Select case when something, then this

When something else while

else no matter what

end fieldname.

Then there are features like ifnull, coalesce, decode, etc..  Here are the specific db.  I do not use MySql so I can't tell you what functions there.

Tags: ColdFusion

Similar Questions

  • the variable name of database query to SQL Server using the Oracle database link

    Hi all

    I have an ApEx 4.1 application running on x 64 (11.2.0.1) 11g on Windows Server 2008 x 64, and I have a few points of data integration with SQL (2005 and 2008) server that I need to create. I have configured the database with dg4odbc link and it works perfectly... I can run queries on the SQL Server database without any problem using the database link.

    However, there is a scenario where the SQL Server database name is dynamic, and I need to generate on the fly in a PL/SQL block and then use it in a query dynamic SQL (all this in the ApEx). It of wherever I meet problems... when I asked the default database that is based on the ODBC connection and I don't have to specify the name of the database, no problem. But when I need access to one of the several other databases by default, I received the error "invalid table.

    It works well:* (note that 'fv' is the name of my database link)

    v_query1: = "select 'Release Date' from dbo." Schedules@FV where dbo. Annexes. "" SchedID "=: calendar";
    EXECUTE IMMEDIATE v_query1 in rel_date using the grid.




    I then take this rel_date variable, convert a varchar2 (rel_date_char), then use it as the name of the database in the following query...


    _ It returns an error(error ORA-00903: invalid table name)

    v_query2: = "select"PARTNO": rel_date_char.dbo.ProdDetails@fv where 'SchedID' =: calendar and"UnitID"=: unit"
    and 'MasterKey' =: master and "ParentKey" =: parent';

    EXECUTE IMMEDIATE v_query2 in part_number using planning, master, parent unit;



    I also tried using all of the following conditions without result:

    "select"PARTNO"of" | : rel_date_char | '.dbo. ProdDetails@fv where 'SchedID '...
    "select"PARTNO"of" | rel_date_char | '.dbo. ProdDetails@fv where 'SchedID '...
    "select"PARTNO"of" | @rel_date_char | '.dbo. ProdDetails@fv where 'SchedID '...
    "select"PARTNO"in @rel_date_char.dbo.ProdDetails @fv where 'SchedID'..."


    Is it possible to do it in PL/SQL?

    Thanks for any help!
    -Ian C.

    Published by: 946532 on July 15, 2012 19:45

    Just did a test using passthrough:

    SQL > set serveroutput on
    SQL > declare
    2 val varchar2 (100);
    3 c whole;
    4 whole nr;
    5. start
    c: 6 = dbms_hs_passthrough.open_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3;
    7 dbms_hs_passthrough.parse@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, "select count (*) from EMP");
    8 LOOP
    9 nr: = DBMS_Hs_Passthrough.fetch_row@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
    10 output when nr = 0;
    11 dbms_hs_passthrough.get_value@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, 1, val);
    12 dbms_output.put_line (val);
    13 end of loop;
    14 dbms_hs_passthrough.close_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
    15 end;
    16.
    24576

    PL/SQL procedure successfully completed.

    SQL > declare
    2 val varchar2 (100);
    3 c whole;
    4 whole nr;
    5. start
    c: 6 = dbms_hs_passthrough.open_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3;
    7 dbms_hs_passthrough.parse@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, ' select count (*) from dbo.) EMP');
    8 LOOP
    9 nr: = DBMS_Hs_Passthrough.fetch_row@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
    10 output when nr = 0;
    11 dbms_hs_passthrough.get_value@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, 1, val);
    12 dbms_output.put_line (val);
    13 end of loop;
    14 dbms_hs_passthrough.close_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
    15 end;
    16.
    24576

    PL/SQL procedure successfully completed.

    So all 3 ways work for me.

    Published by: kgronau on July 23, 2012 10:08

    Now, using the variables to make the selection:

    SQL > declare
    2 val varchar2 (100);
    3 c whole;
    4 whole nr;
    5 tabname varchar2 (20): = 'EMP ';
    6 ownr varchar2 (20): = "dbo."
    7 dbname varchar2 (20): = "door";
    Start 8
    c: 9 = dbms_hs_passthrough.open_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3;
    10 dbms_hs_passthrough.parse@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, ' SELECT count (*) FROM ': dbname: '.) ' || ownr | '.'|| tabname | ") ;
    11 LOOP
    12 nr: = DBMS_Hs_Passthrough.fetch_row@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
    13 when the exit nr = 0;
    14 dbms_hs_passthrough.get_value@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c, 1, val);
    15 dbms_output.put_line (val);
    16 end loop;
    17 dbms_hs_passthrough.close_cursor@FREETDS_DG4ODBC_EMGTW_11_2_0_3 (c);
    18 end;
    19.
    24576

    PL/SQL procedure successfully completed.

    => instead of executing the statement using the "execute Immediate" we use the PASTHROUGH package to pass the statement to SQL Server.

    Published by: kgronau on July 23, 2012 10:10

  • common file to store the variable

    I'm going to start a new project using ColdFusion and would like to have a common file to store my variables.

    I would like to know ColdFusion has any specific file to store such as Web.Config ASP.net or can I have my own file name?

    Your information and help is much appreciated,

    Kind regards

    Iccsi,

    You can have a file called anything you like and just cfinclude it.  However, you may be better of just using SystemFramework (onSessionStart, onRequestStart) in your application.cfc and create your variables directly in there.  Application.CFC (and application.cfm) are the closest ColdFusion has to a 'common' file - what is called of all page requests that pass through the ColdFusion server.

  • In the variable name variable

    Hi guys/girls.

    I have a problem, I have a number of tables of items called "pres1", 'pres2', 'pres3', etc.

    I have a variable which will be 1, 2, 3...

    the amount of the variable goes up will always be the same amount as the number in the name of the table. That is to say if the berries go up to "pres6" the variable will go does not exceed 6

    I want to access the data in my table based on the currently set number variable

    IE: If myVar = 2, I want to access the data in "pres2.

    I'm sure that its probably something very simple and im just getting the syntax wrong, can anyone help?

    Thanks in advance

    If press1, press2, etc. are names of variables in the current scope, use:

    trace (this ["press" + myVar] [1]);

  • evaluate the variable name in a loop in cs3

    I want to generate names of variables in a loop and assign it a library object.

    e.g. public var missing1_mc:MissingGameObjects;
    public var missing2_mc:MissingGameObjects;
    public var missing3_mc:MissingGameObjects;
    public var missing4_mc:MissingGameObjects;

    Now, in a loop, I want to do the following:

    var ClassReference: Class;
    var missing_obj:String;

    for (var i = 0; i < usedNo.length; i ++) {}
    missing_obj = main_obj + usedNo [i] + '_', '_x ';
    ClassReference is getDefinitionByName (missing_obj) classroom;.
    'lack' + (i + 1) + "_mc" = new ClassReference(); wrong code
    'lack' + (i + 1) + "_mc".setpos (150 100); wrong code
    }

    How could I do that. Any help is appreciated.

    If you try to use the object variable names and classes of the variables, you can use the following (assuming that everything is set):

  • retrieve the value column access via the variable name of the column

    I need to build a function of validation with this condition:

    The data model is like this:

    We have an array of items_general, with its id and data.

    Then we have specific tables, let's say... item_especific1, item_especific2 item_especificn. They have the same as the table of the item_general pk and fk against item_general

    Each element is in one of the tables item_specific and items_general.


    Now, the validation feature: I need to check for an element, if some special columns of the item_especificx table are null and will raise an error if this occurs.

    I got the name of especific_table and the list of names of particular column stored in another table.


    I guess I can browse this list of column table to build a clause concatening Dynamics 'and' | column_name | 'is nothing', but I'm not a big fan of the dynamic sql.


    Can you think of a better solution? Any way to access the value of the column by using the column name, as if it were a varchar2 key index?




    Nope, no filter.

    When you have a funky data like that model, you're destined to dynamic sql and other assortment of headaches.

  • store the resource name of visa in variable teststand

    Hello

    can I store a VISA resource name in a variable of teststand using the property api set of labview?

    If Yes, then I know how?

    concerning

    Giri-

    HI Giri,

    You can store as a string Variable in the TestStand using the "set property - value chain.

    Kind regards
    Nitz

    (Bravo to give good answers, mark it as a Solution If your problem is resolved)

  • increment the variable names - how can I do? Google Maps API

    I am trying to integrate google maps into my website. I want the user to be able to view the current customers of my company.

    Can I query my database and get name, longitude and latitude of the customer.

    I can do only one marker on the map like this:

    var marker = new GMarker (new GLatLng (< cfoutput > #geoip.testilat # < /cfoutput >, < cfoutput > #geoip.testilong # < /cfoutput >));
    GEvent.addListener (marker, "click", function() {}
    var html = ' < div style = "width: 210px;" padding-right: 10px "> < cfoutput > #geoip.schoolName # < / cfoutput > < br > < cfoutput > #geoip.text # < / cfoutput > < \/div > ';"
    marker.openInfoWindowHtml (html);

    });

    map.addOverlay (marker);

    GEvent.trigger (marker, "click");

    But I need to browse the database and create a marker for each line with a different variable for each name, IE. marker, marker1, etc...

    I know that I have to build some kind of loop, but I don't know how. Can someone point me in the right direction?

    Thank you

    currentRow is created by the closure of over a Recordset created by a

    I imagine that in your code example geoip was a record set from a query.  If this isn't the case, you can use any variable for which is convenient for your logic.

  • Where EAS stores the server names?

    We migrated to new servers in production. Now the problem is all BR users need to connect to EAS and manually add the essbase server. If they do not, they are unable to see the new essbase server in the drop in HBR.

    So that got us thinking, there must be a file where these server names are stored? This file may be migrated and then users do not need to add servers all over again.

    Reading of more to life than that...: where EAS stores user information it should have all the information you're looking for.

    See you soon

    John

    http://John-Goodwin.blogspot.com/

  • Prevent the specific Web site to store the user name in the drop-down list

    I have a site that I connect to frequently. Their home page has a login field. If I double-click on this area, it shows me several login names to automatically fill the area with. I want to prevent Firefox (or other) to remember those login names, for safety because of my personal paranoia.

    I'm using Firefox 49.0.2.

    • I added this site to my list of blocking Cookies. New Cookies are not displayed to the top, when I connect.
    • I do NOT have the connections stored for this site (they were removed and new not appear when I enter a name).
    • Firefox does NOT show me the dialog box "do you want to remember?
    • I removed each stored in AutoComplete list in this field by using the 'shift + Delete' keys to select and delete the headings that appear when I double click on the field.
    • The list that appears when I double click is NOT specific to this site... or rather, the entries in the list seem to come from almost any site that I connected. For example, I have deleted all entries in this site, I worry; I have then is come to Mozilla's Support forum and tried connecting; I had to try several times; all of these names that I used on the login field Mozilla now appear in the list for the original site.
    • Curiously... If I hit 'back' after typing my name (causing the site to go to the next page), the name that I typed in the field seems NOT to remember. However, if I click on the button "login" next to the field after you type a user name, the name seems to remember.
    • Even if I disable 'Remember connections... ". "in Firefox, UN I enter this field to remember.

    A screenshot is provided the field of seizure and the drop-down list of names (which I deleted several times).

    I turn off history form of Firefox, so I don't know if this is specific to the site (such as the saved connections) or could possible appear on all sites with a named field in a similar way, which seems a little odd.

    If you clear history of Firefox form feature, is the unwanted suggestion stop appearing? You can do this on the preferences page, Privacy panel:

    "3-bar" menu button (or Firefox) > Preferences

    In the left column, click on privacy. On the right side, if you do not see "conservation rules: use the custom settings for history" go ahead and make that choice.

    Then you can uncheck the box ' Remember search and form history.

    When you return to the site and reload the page, the suggestions disappear?

  • JavaScript or advanced action help to increment the variable names

    I hope someone with Javascript skill can help me here. And it could also be possible with tip action, but I can't do it.

    I have a 'NombrAl' variable that chooses to enter 1 to 128 on blade.

    I have a series of variables - "but_word_1", "but_word_2" "but_word_3" etc all the way to "but_word_128".  They have text string values.

    I have another variable "spoken_word.

    By clicking on a button, I would like to that Javascript to define "spoken_word' with 'but_word_' + 'NombrAl '.

    e.g. If NombrAl then is 5 - window.cpAPIInterface. setVariableValue ('spoken_word', but_word_5);

    Thank you.

    Try this:

    window.cpAPIInterface.setVariableValue ("spoken_word", window.cpAPIInterface.getVariableValue ("but_word_" + NombrAl));

  • Store the file names and then display then in order

    Hello

    I have a procedure that writes about 10 files on drive DB...
    as
    File1. XML
    File2. XML
    file3. XML
    .
    .
    .
    file10. XML

    My question is should I capture these names and put them in a text file and load them with files generated in DB drive...

    However, I have to use a table to load these names, then write them in the text file and then delete after each race...

    any suggestions... ?
    Thnx

    Something like

    v_conts_file := 'Something.txt';
    f_conts_file := utl_file.fopen(v_out_dir, v_conts_file, 'W');
    .
    .
    v_filename := v_mail_code.xml';
    f_xml_file := utl_file.fopen(v_out_dir, v_filename, 'W');
    utl_file.put_line(f_xml_file, v_RECORD_DATA);
    .
    .
    .
    .
    .
    utl_file.FCLOSE(f_xml_file);
    .
    .
    utl_file.put_line(f_conts_file, v_filename);
    
  • How can we use the variables name, for example?

    I use 9 textbox in my step. The names are similar, only difference is the last character. (s1_0, s1_1, s1_2,...). I am using these textbox in a loop. But I couldn't find the right typing... s1_ [i], (i) s1_ or s1_ {i} gives an error.

    s1_0.text = 0
    s1_1.text = 0
    s1_2.text = 0
    s1_3.text = 0
    s1_4.text = 0
    s1_5.text = 0
    s1_6.text = 0
    s1_7.text = 0

    How can he do the shortest hits for this problem?

    Use the operator [] table:

    for (var i: uint = 0; i<>

    This ["s1_" + i.ToString ()] .text = 0;

    }

  • Increment the variable NAME

    To create 10 buttons, you don't have to create them manually (button1, button2, button3, etc), instead, it is possible to create using a loop for,.

    for (var i: int = 0;  I have < 10; i++){

    create a new button with the name + button (i)

    }

    Can someone refresh my memory what would be the proper syntax for naming the new button so that the maes are incremented just?

    Thank you

    Hello

    This should cover

    for (var i: Number = 1; i< 10;="">

    {

    var mybtn:Button = new Button();

    mybtn.ID = "btnID" + String (i);<=== set="" id="">

    mybtn. Name = "btn_" + String (i);<=== set="" name="" if="" you="">

    What ever you set for each btn as listeners to click.

    }

    David

  • Retrieves the name of the variable

    Hello

    I'm trying to change the OpenG changed? Subvi (see below) so that he will write the new value of the variable sent to 'Variant' if changed on the disk (using the following config VI). To do this, I need to somehow extract the variable name of the variable (any type) which was connected to the entrance of variant of the changed? Sub - VI by VI calling so that I can use it as a key name. Is this possible? This information is still transmitted to the Subvi?

    If you use openg, there is a "Get the name of data" function that retrieves the name of the data passed in the Variant.

Maybe you are looking for

  • Portege R700-184 freezes + high speed fan

    Hi all I am a happy owner of a unused R700, bought in conditions under renovation.But as far as I can see, it has not been used since around 2011, and judging by the box was stored in a warehouse and was used. I installed Windows 7 64 bit I need to u

  • Error 1402: LV 2013 64B on W7pro

    Hi all! I try to install 2013 LV on W7 64 bit, but I have this error directly: See attached file photo A So I test the protrocol set here and just after the change of the access authorization of parent folder, I have this message: See attached file p

  • Upgrade of Ram 4 GB DDR3-1600 MHz

    HI friends I use a laptop HP G62-361TX, can I upgarde RAM of 4 GB of DDR3 memory at 1600 MHz

  • How to get the link to my own question, I asked before!

    I asked 2 days before, but I m not getting issue is not its link and respond accordingly. How do I find that?

  • SUBSCRIPCION ACTIVACION

    I HAVE A MONTHLY PAGO ABONO Y ME DA ERROR OF ACTIVATION OF THE SUBSCRIPCION IN PREMIERE PRO