Through a set of query results, replacing one string by another.

I want to write a function that replaces the occurrence of a string with another string different.  I need to be a CF fuction which can be called from another function CF.  I want to 'hand' this function (a string) SQL statement like this: (Please note, don't bother commenting "there are ways of writing this SQL try..., I made this simple example to get to the point where I need help.)  I have to use a 'sub_optimal' SQL syntax just to demonstrate the situation)

Here's the string I want to pass to the function:

SELECT

[VERYLONGTABLENAME]. FIRST NAME,

[VERYLONGTABLENAME]. LAST_NAME,

[VERYLONGTABLENAME]. ADDRESS

Of

LONGTABLENAME [VERYLONGTABLENAME]

Here are the contents of the ABRV table:

TBL_NM, ABRV <! - header line - >

VERYLONGTABLENAME, VLTN

SOMEWHATLONGTALBENAME, SLTN

MYTABLENAME, MTN

ATABLENAME, ATN

The function returns the string origin, but with the abbreviations in place names of the long table, example:

SELECT

VLTN. FIRST NAME,

VLTN. LAST_NAME,

VLTN. ADDRESS

Of

LONGTABLENAME VLTN

Notice that only the table brackets and names that match a value in the table ABRV were replaced.  The LONGTABLENAME immediately following the FROM is left as is.

Now, here's my attempt at amateur said written dum function: Please look at the comment lines for where I need help.

< name cffunction output = "AbrvTblNms" = "false" access = "remote" returntype = "string" >
< name cfargument = "txt" type = "string" required = "true" / >

< cfset var qAbrvs = "" > <! - variable to hold the results of the query - >

< cfset var output_str = "#txt #" > <!-I create a local variable so I can manipulate the data returned by the parameter TXT.  Is it necessary or can I use the parameter txt? ->


< cfquery name = "qAbrvs" datasource = result "cfBAA_odbc" = "rsltAbrvs" >
SELECT TBL_NM, ABRV FROM BAA_TBL_ABRV ORDER BY 1
< / cfquery >

<!-I'm assuming that at this point, the query is executed and records in the result-> set

< cfloop index = list "idx_str" = "#qAbrvs #" > <! - is - right?  I do not. ->
< cfset output_str = Replace (output_str, "#idx_str #",) <! - is - right?  I do not. ->

< / cfloop > <!-who am I loop on?  What is the index? How to do the replacement of the chain? ->

<!-the chunck, below is a partial of my Object Pascal from Delphi function that does the same thing

I need to know how to write this part in CF9
So what not of folklore
Start
s: = StringReplace (s, ' [' + FieldByName('TBL_NM').]) [AsString + ']', FieldByName ('ABRV'). AsString, [rfReplaceAll]);
Following;
end;
->

< cfreturn output_txt >

< / cffunction >

I am mostly struggling with the syntax here.  I know what I want to do, I know how to get there in a different programming language, just not CF9.  Thanks for any help you can provide.

RedOctober57 wrote:

...
Thanks for any help you can provide.

One:

 

No you need not create a local variable that is a copy of the variable arguments that the scope of the arguments is already local to the function, but you are not referencing correctly the scope of the arguments, then you may be using a variable 'txt' in another scope.  So best practice would be to refer to "arguments.txt" where you must.

Two:

I know what I want to do, I know how to get there in a different programming language, just not CF9.

Then a best start would be to descirbe what you want to happen and give a simple example in the other programming language.  Most of us is muti-lingual and can analyze code in any clear and clean syntax.

Three:

     

I think you want to be a loop on your recordset returned by the previous query, perhaps 'qAbrvs '.


Four:

Continuing on this assumption I suppose you want to replace each instance of the long chain with the short form string that record together.


Five:

              

If this is true, then you loop through the set of records from tablenames and abbreviations that you want to replace the chain.

Tags: ColdFusion

Similar Questions

  • How to replace one table with another?

    I need to replace one table with another. Both tables have the same structure, primary keys, indexes, constraints, but different data (about 50 million records).
    I would like to make this replacement in line, with no passage of database in offline mode.
    There is no clause CREATE or REPLACE TABLE in Oracle unfortunely.
    I could use just DROP and ALTER TABLE RENAME instructions, but it is necessary that a user receive message error "table or view does not exist. It may be possible to block incoming requests at the moment, while old and new droppping table rename are performed?

    Thanks in advance.

    Hi again!

    You can detect normal users with session sessions $ v. A session of a normal user has a username (username of the column). Systemsessions PMON and SMON have no user name. So, you can use the following query to detect sessions, you need to kill:

    SELECT sid, serial#, username
    FROM   v$session
    WHERE type NOT LIKE 'BACKGROUND';
    

    concerning

  • Why ps automatically replaces one font with another?

    I have a PSD with text block. any time I opened the file ps (5.5) replaces my police by another. I got this info 'some text layers may need to be updated before they can be used for vector output.  You want to update these layers now? »

    Two possibilities come to mind:

    1. the PSD file is a text layer that refers to a font that is not on your (most likely) system. If you are upgrading day and re - register (I recommend under a new name), the warning must away, but your text layers will have been activated using the substitute font. This could be allowed, or it might not, depending on your objectives and your needs. To dismiss the problem on the original file, you will need to find missing fonts and make sure that it is installed in your system. It's a good idea to restart Photoshop after the installation.

    2. one of the more fonts on your system are corrupt (less likely). There are procedures that you must follow in order to find, remove and replace or repair the corrupt police, depending on your operating system. A google search on "How do to find and fix corrupted fonts" should prove fruitful. I recommend you start by various Youtube videos.

  • run immediately and the set of query results

    Hi gurus,

    I want to create a series of paintings on the fly using run immediately.
    the table_names are stored in another table work_table.


    run immediately (select 'create table' | table_name |) '(id int)' of
    * (select table_name in work_tables)); *


    This will raise error.

    ORA-06550: line 1, column 18:
    PLS-00103: encountered the symbol "SELECT" at the expected in the following way:

    (en) - + new case mod not null < an ID >
    < between double quote delimited identifiers of > < a variable binding >


    instead of using a cursor to run one by one is the lines an alternative solution?

    Thank you very much
    Charles

    May not know why you want to do it in a single statement, anyway:

    SQL> select * from work_tables;
    
    TABLE_NAME
    ------------------------------
    x1
    x2
    
    SQL> declare
      2  str varchar2(32000);
      3  begin
      4    for r in (select table_name from work_tables) loop
      5      str := str || 'execute immediate ''create table ' || r.table_name || '( id int )''; ' ;
      6    end loop;
      7
      8    execute immediate 'begin '||str||' end;';
      9
     10  end;
     11  /
    
    PL/SQL procedure successfully completed.
    
    SQL> desc x1
     Name                                                        Null?    Type
     ----------------------------------------------------------- -------- ------------------------------
     ID                                                                   NUMBER(38)
    
    SQL> desc x2
     Name                                                        Null?    Type
     ----------------------------------------------------------- -------- ------------------------------
     ID                                                                   NUMBER(38)
    

    Max
    http://oracleitalia.WordPress.com

    Published by: Massimo Ruocchio, February 18, 2010 15:03

  • How to replace one image with another

    I have a page that displays the results of a search for information about a club. One of the elements is the logo of the club. It is displayed by using the following code

    < img src = "<?" PHP echo $row_clubedit ["club_logo_url"];? ">" alt = "Logo of The Club" class = "logo" title = 'in the Club Logo">

    It works fine, except when no club has been selected, in which case it indicates the default polling point in a blue box.

    It would be nice if I could display the Logo of the Federation, to which all clubs belong, until a club is chosen.

    Y at - it a simple way to define a default image that would be replaced from a set of data.

    $row_clubedit ['club_logo_url'] contains the url in the log format http://www.Club.org/clublogo.PNG

    < img src = "<?" PHP echo ('federation_logo_url');? ">" alt = 'Logo of The Club' class = 'logo' title = ' The Club'c Logo ">

    The logic I guess would be

    If there is no such thing as club_logo_url

    then print the logo of the Federation,

    otherwise print the logo of the club.

    How you code that in php?

    I am only a beginner in PHP.

    "http://www.club.org/clublogo.png": $row_clubedit ['club_logo_url'];? "". ">" alt = "Logo of The Club" class = "logo" title = 'in the Club Logo">

    must be done

  • replace one image with another

    I have two images of the same radial venn diagram, created in Powerpoint. I caught the with Jing and create png: ILM_model and ILM_Mod1 (see images below).

    I want an image to blend into one another, so it seems that I am just pointing out the Center and support node. I tried simply fade on while the other fades in, but I get this weird distortion of red and yellow on the edges in the cross-fading. In addition, the image quality is deteriorated. I took a screenshot to show you.

    http://screencast.com/t/nygksaVXTJ

    ILM_model.pngILM_Mod1.png

    Check the quality setting on the slide/s where you have this diagram and the value of high quality.  Your screencast looks like you could use only the low quality (8 bits) at the present time.

  • How can I programaticaly replace one Enum with another within a cluster

    Hello

    You can do that running. This requires a change in data type, which in fact means the application tries to change its own code (i.e. itself) and which is not allowed. You can use the script to replace things, but that is an edit operation, not a runtime operation.

    You can either replace this enum with a string, or you can use several controls as you had alluded.

  • Replace a pic with another pic / replace one image with another

    Hello

    I created a symbol with a photo and text. I duplicate my symbol and now I'll like to replace my pic duplicated using a new peak. Perhaps, it's simple, but I can't find the way :-(

    Hello

    I created a symbol with an image and text. Symbol of my I duplicated, and now I'd like to replace the image of my new symbol by another. Maybe it's simple, but I have not found how to do :-(

    If you want 2 symbols with different images, you need to duplicate the symbol in the library and then swap the image on them.

    or you can change the image in the code with attr or css.

  • How can I transfer a project that resulted from one computer to another without the export option?  My computer won "work on export control.

    How can I transfer a file of 532 images, which have been improved in Lightroom, to another computer without

    using the export option?

    My computer will not export.

    It is not a question of DISK SPACE.

    It is a memory problem. You don't have enough MEMORY.

    Temporarily, you should try to export with all other applications closed. In the long term, you must have BOTH a 64-bit operating system and 8 GB of memory.

    If I were you, I would ask your computer to change the computer to a 64-bit operating system.

  • Verification of an element in one string from another string

    Hi guru,.

    I have 2 strings separated by commas. Say it like that.

    a VARCHAR2 (100): = '1,2,3,4,5,6,7,8,9,10';
    b VARCHAR2 (100): = '2,6,9';

    My requirement is like I want to check the chain has, if it has all of the b element. I am using the regular expression. But I wasn't able to do.
    Kindly help me.

    Kind regards
    VJ

    Hello

    I'd probably use the Michaels, but if you want to see how you could do this using regular expressions:

    SELECT     *
    FROM     table_x
    WHERE     REGEXP_LIKE ( ',' || a || ','     || '/' ||
                    ',' || b || ','
                  , '(,[^,]+,).*/.*\1'
                  )
    ;
    

    where "/" is known not either a or b.

  • Regex to check if there is one string within another string

    What is the best regex to check if there is a string within another string?

    It does not work:

    var regex: RegExp = new RegExp ("/ ^.") + "+ myString +". + $/") ;

    Another yew (st.search (regex) == - 1).

    If the search fails, the value returned is - 1, no false or 0.

  • [CS2] [JS] Replace one special character with another

    Hello

    I want to replace one specialCharacter by another in a SpecialCharacter.ForcedLineBreak, but research use only the string.

    That is right. Since you cannot enter SpecialCharacter constants in the search (and replace) the strings, you must use escape inside regular channels codes. Fortunately, these are exactly the same as in the program itself: ' ^ =' for dash, ' ^ is to the fixed space and so on. Forced line break isn't that ' ^ don't?

  • How to clear the search query result set

    I dropped a search with the table query. When I search a value it is the display of the result, but when I click on the reset button, only the query Panel is reset to zero and not the table. What can I do to reset the table component associated with the query?
    When I click on the reset button, only the query panel goes to zero and no table.

    It will be reset nt table.

    What can I do to reset the table component

    Use of the component range reset. to do so.

    http://jobinesh.blogspot.in/2009/10/reset-content-of-Web-page.html
    http://myadfnotebook.blogspot.in/2011/05/making-reset-button-in-afquery.html trickles you want
    http://andrejusb.blogspot.in/2009/09/programmatical-reset-for-query-results.html

    -edited lately

    Published by: ADF7 on February 22, 2012 12:58 AM

  • Keep the query results set all paging

    I have a query back thouands of records. For do not impact performance display and paging, which would be the best way without use of query caching? Is it possible to keep the first recordset query time she and her use in Exchange?

    Load balancing definitely throws a wrinkle by using shared memory.  There are ways to address these problems, but they all come with the pros and cons, just basically choose what pros like you and what the disadvantages that you can live with.

    I.E. you can use sessions.  So when a user first access your application, all future queries are sent to the same server that processes requests for first.  But this means that if this server will see, all users currently glued to it are s.o.l.

    I saw other people using databases for the persistent memory.  But then, you have the LAG involved in obtaining data from the database on every request, although it should be easy fast queries to do this.  Side pro, it does not matter which server processes the request.

    It would be different then just re - run the original query every time, but rather store the original query results into a temporary table space so that any complexity which may exist should not be repeated.

  • How to filter through a set of data based on user input

    Hi all

    I'm trying to filter through a set of data, purchase only the files that meet the requirements of users.

    I ask the user to enter three different values, one for a frequency to start another for a frequency of end and also the value of the rated power.

    The way I am filtering from now thanks to this data set is using a function called the regular expression function as well as the analysis of string function to break up the name of file and data digital take-away, then compare these data on the entries of users.

    These values that meet the conditional statement will be sent to a ring of results for a user to go through.

    For now, I filled it is not as much functionality in this method, the user must be very careful in the way which he or she saves files and my program may work correctly.

    I am ataching a photo of this part of the program.

    Thanks for the help.

    I think that my second statement should check on a white paper OR PDM.  Have you noticed the color?  This is a clickable link.  If you read the material here, it should clear up confusion in the first part of my post.

    I have a colleague who, like you, encodes the parameters of the study of the (very long) string of the name of the file.  I always shout at him about it, because it requires him (because you are considering do) build routines for (a) analyzes the names (to retrieve the information hidden in them), (b) to organize the data in a form of "LabVIEW Database" and then (c) figure out how (in LabVIEW) for write "queries" on this database.  More file names are not particularly easy for a human to read, are extremely long and invite more mischief (have you thought about putting your files in folders which are similarly 'file-information-coded'?  Becomes even more messy more fast).

    You might think Oh, "it's too late to make a change, I have already all of these data", but what good is it if you can't analyze easily, group them, sort, etc. ?

    Bob Schor

Maybe you are looking for

  • Cannot record software instruments

    It is so fundamental that I should be ashamed. Widely used older versions of GB, but I come to him with El Capitan and V 10. I set up a track record, choose my software instrument, as always, press record and the light, the track head moves on the sc

  • computer crashing on long import map

    Sorry, I know I have seen this answered before but this could not be found on a search I have I apologize.  Still works with FCP 7 and I'm trying to import a very long clip. Probably close to a long time: 45 captured in AVCHD on card scandisk.  Short

  • Toshiba Gigaframe Q81 and video playback

    Hello I am convert mpg to AVI via the supplied + Media Converter 2.5 + but audio and video soon go out of sync!He plays very well through Windows Media player, etc. on a pc! Does anyone know a fix?Thank youPaul

  • Can connect but can not map or access by car.

    I had to close my network because co to replace the transformer. When I restarted the network 2 of my computers worked fine the other 2 cannot access drive maped. I restarted the 2 that will drive network, tried remapping drive access (got error mess

  • Headphones with a handset connector

    Hi all! For some time I can not find a headset for T410. The helmet must have a combo connector, and that's the problem. All the of Atria in my city have 2 connectors separated, and none have a combo connector. I don't like headphones from apple-phon