Tuesday, December 6, 2011

SQL IN statement

Hi,



I'm trying to run a query that looks something like this



%26lt;cfquery name=''test'' datasource = ''ds1''%26gt;

SELECT *

FROM tblTest

WHERE '#variables.test#' IN (txCommaDelimitedList)

%26lt;/cfquery%26gt;



where variables.test is an integer and txCommaDelimitedList
is a database field like '100','101','102'. This doesnt work
though. Any ideas?SQL IN statement
Normalize your database and you won't have problems like
this.SQL IN statement
You'd need to loop over variables.test and create dynamic
statement.



%26lt;cfset tempSQLStatement =''WHERE
#listFirst(variables.test)# IN (txCommaDelimitedList)'' /%26gt;



%26lt;cfloop list=''#listRest(variables.test)#'' index=''i''%26gt;

%26lt;!--- you could also use OR ---%26gt;

%26lt;cfset tempSQLStatement = ''AND #i# IN
(txCommaDelimitedList)'' /%26gt;



%26lt;/cfloop%26gt;



%26lt;cfquery name=''test'' datasource = ''ds1''%26gt;

SELECT *

FROM tblTest

#tempSQLStatement#

%26lt;/cfquery%26gt;
Whats the error you get?
Actually, my example was bad. It should have read:



SELECT *

FROM view_test

WHERE '#variables.test#' IN (txCommaDelimitedList)



It's a view where txCommaDelimitedList is a field which
contains a comma delimited list of integers based on the results of
a query of an xref table.



No errors. Just no results.
Why is variables.test in quotes?
bc txCommaDelimitedList is a varchar field since it has the
commas in sql
so which one is your field, and which one is your set of
values? You can NOT do this:



SELECT something

FROM table

WHERE 'value' IN (COLUMN_name1, COLUMN_Name2, etc.)



This is invalid SQL!



Should be more like



WHERE COLUMN_Name IN('value','value','etc.')



Phil
I can see a few obvious problems with the SQL:



1) You should not use quotes surrounding #variables.test#.
The resulting SQL should be:



WHERE myCol IN (myList)



and not

WHERE 'myCol' IN (myList)



2) You don't have txCommaDelimitedList surrounded by pound
signs, so CF is treating it as the literal text:
''txCommaDelimitedList''. Look into using %26lt;cfqueryparam%26gt; you
can use the list=''Yes'' parameter to handle comma delimited lists
(even integers).



WHERE #Variables[''test'']# IN (%26lt;cfqueryparam
cfsqltype=''CF_SQL_INTEGER'' value=''#txCommaDelimitedList#''
list=''Yes''%26gt;)



3) Using a CF variable like that in your query statement is
incredibly insecure. You're pretty much setting yourself up for a
SQL injection attack. You might look into using a switch/case
statement, or at least performing an initial query to make sure
that Variables.test is a valid column name and not something like:



1=1;

DROP TABLE

SELECT * from SomeTable WHERE 1


I'll echo what Dan said:



%26gt; Normalize your database and you won't have problems like
this.



What you're trying to do is not possible:



WHERE 'cfvariable' IN (databasecolumn)

where the databasecolumn contains values like this:

'''101','200','204','204'''



You're trying to do a reverse IN. SQL IN statements are meant
to check a database column against a comma-delimited list of
values, not the other way around (a value against a column in your
database that contains a comma-delimited list of values).



You need to fix your data model.
My 2c,



Because fshin has said


quote:



It's a view where txCommaDelimitedList is a field which
contains a comma delimited list of integers based on the results of
a query of an xref table.





I would then say the db may be normalized.



Questions:

How does the cf page access this ''view'' ?

Can you change the ''view'' or pass in a parameter ?



The query you are trying to perform can't be done.



Maybe easier to use list functions to see if the ''test'' value
is in the ''view'' list, then use the result in a query.



Ken

FLV playback considerations

What other factors can affect the quality of playback of an
FLV from an HTTP server? Here's the situation...



I have 3 machines here...2 of them will play an FLV from our
site easily at 30 fps. SpeakEasy and DSLReports tests show our
download rate at 5+MB at all 3 PC's. The 3rd PC can only play at a
noticeably jumpy 10 - 15 fps. Granted, the 2 machines playing 30
fps are powerful - one's a dual Xeon 3.0gHz, and the other a Intel
Dual Core 2.83gHz. The slow puppy is a P4 2.x gHz.



All have the latest Flash 9 player.



FLV playback considerations
Well...we had placed one of the videos on YouTube, so we
tried that version on the slow PC...It plays smoothly. So, there's
something in my encoding settings. I usually use Sorenson Squeeze
to encode with the VP6 384K setting.
  • girl lipstick
  • Set Maximum number of LOG IN failures

    I have password protected pages and would like to find a way
    to limit the number of failed login attempts by a user. Is there
    code to use. I am using DW 8 in ASP and the 'LOG IN USER' server
    behavior. I am recording the 'REMOTE_ADDR' server variable and the
    time-date of the login. Can this help i would like to block a IP
    address for a set time if more than 3 log in attempts fail. Goto


    http://www.gohbcc.com/CallCenter/LOGIN.asp

    username; admin

    password; 1234

    Thanks MikeL7Set Maximum number of LOG IN failures
    Have your login form send users to a second script page....



    %26lt;form name=''form1'' method=''post''
    action=''secondpage.asp''%26gt;



    ... that compares results against the database and adds
    criteria based on the failed response, and redirecting users
    appropriately.



    rs(''LastLogin'') = date()

    rs(''ip'') = Request.ServerVariables(''REMOTE_HOST'')

    rs(''loginstatus'') = ''blocked''

    rs.Update



    You can update fields into that users recordset when they
    login. Add fields into the DB table as needed (above is just an
    example of criteria you may wish to capture)



    Add the redirects based on your recordset queries



    if ip = '''' THEN

    response.redirect ''whereever they are going.asp''

    elseif ip = ''duplicate ip address'' THEN

    response.redirect ''failed logins .asp''



    else

    response.redirect ''login.asp?err=true''



    end if





    You can get as fancy or simple as you want. for example, you
    could have multiple criteria for each response redirect. You just
    have to make sure you define the variables...



    ip = rs(''ip'')

    or

    session(''name'') = rs(''name'')

    etc.



    Make sense? Ditch the premade stuff that dreamweaver uses and
    create your own login scripts.

    Calculations

    Hi there, I took the TipCalculator2.as from the flash 8
    Samples folder and modified it to be a 401k calculator. Everything
    seems to be working %26amp; calculating correctly except when I
    select the radio for ''Per pay period'' and then change the ''Percent
    to Contribute'' value, it reverts back to calculating it ''annually''
    instead of ''Per Pay Period'' which simply devides annual by 24.



    Can someone take a look at this code and help me determine
    why it reverts back to calculating it annually instaed of per pay
    period even though i've selected the radiobutton to calculate it by
    pay period?



    Do I need to seperate the functions? I'm confused....



    Here is a sample to view/test with:




    http://home.comcast.net/~shane.swoboda/four01k.html



    And here is my class file:



    //

    // four01k.as

    //

    // This is an example of event handling

    // and V2 components of Flash MX Professional 2004

    //



    import mx.controls.TextInput;

    import mx.controls.RadioButton;

    import mx.controls.RadioButtonGroup;



    class four01k extends MovieClip

    {

    // Declarations for the various components

    var subtotal:TextInput;

    var gratuity:TextInput;

    var increase:TextInput;

    var contribLabel:TextInput;

    var combinedLabel:TextInput;

    var radioGroup:RadioButtonGroup;

    var percentRadio1:RadioButton;

    var percentRadio24:RadioButton;



    // Initialization routine

    // Add event handlers for the subtotal text input and

    // the percentage radio buttons.

    public function onLoad():Void

    {

    subtotal.addEventListener(''change'', this);

    increase.addEventListener(''change'', this);

    gratuity.addEventListener(''change'', this);

    contribLabel.addEventListener(''change'', this);

    combinedLabel.addEventListener(''change'', this);

    percentRadio1.addEventListener(''click'', this);

    percentRadio24.addEventListener(''click'', this);

    }



    // Utility routine for converting a numeric amount

    // to a dollars-and-cents string

    private function formatCurrency(value:Number):String

    {

    var cents:Number = Math.round(value*100);

    var result:String = Math.floor(cents/100) + ''.'';

    cents %= 100;

    if (cents %26lt; 10) {

    result += ''0'';

    }

    result += String(cents);

    return result;

    }



    // Recalculate the gratuity text field based on the

    // subtotal input by the user, and the current

    // tip percentage

    private function calculate():Void

    {

    var percent:Number = Number(increase.text)/Number(100);

    var atotalinvested:Number = Number(subtotal.text) * percent;

    var atotalannual:Number = atotalinvested / 1;

    var hipercent = (.06);

    var contribpercent:Number = Number(increase.text);

    if (contribpercent %26gt;= (.07)) {

    contribpercent = hipercent;

    }

    var totalcontrib:Number = Number(subtotal.text) *
    contribpercent / (1);

    var totalcombined:Number = totalcontrib * .50;

    var atip:Number = totalcombined;

    if (isNaN(atip)) {

    contribLabel.text = '''';

    } else {

    contribLabel.text = formatCurrency(atip);

    }

    var btip:Number = atotalannual;

    if (isNaN(btip)) {

    gratuity.text = '''';

    } else {

    gratuity.text = formatCurrency(btip);

    }

    var empcont:Number = Number(gratuity.text);

    var corpcont:Number = Number(contribLabel.text);

    var totalcont:Number = Number(empcont+corpcont);



    combinedLabel.text = formatCurrency(totalcont);

    }



    private function calculatesemi():Void

    {

    var hipercent = (.06);

    var contribpercent:Number = Number(increase.text);

    if (contribpercent %26gt;= (.07)) {

    contribpercent = hipercent;

    }

    var totalcontrib:Number = Number(subtotal.text) *
    contribpercent / (24);

    var totalcombined:Number = totalcontrib * .50;

    var atip:Number = totalcombined;

    if (isNaN(atip)) {

    contribLabel.text = '''';

    } else {

    contribLabel.text = formatCurrency(atip);

    }



    var percent:Number = Number(increase.text)/Number(100);

    var totalinvested:Number = Number(subtotal.text) * percent;

    var totalsemi:Number = totalinvested / 24;

    var dtip:Number = totalsemi;

    if (isNaN(dtip)) {

    gratuity.text = '''';

    } else {

    gratuity.text = formatCurrency(dtip);

    }



    var empcont:Number = Number(gratuity.text);

    var corpcont:Number = Number(contribLabel.text);

    var totalcont:Number = Number(empcont+corpcont);



    combinedLabel.text = formatCurrency(totalcont);

    }





    // Event handler for ''change''

    // If user changes subtotal, recalculate gratuity

    public function change(event:Object):Void

    {

    if (event.target == increase, subtotal, gratuity); {

    calculatesemi(), calculate();

    }

    }



    // Event handler for ''click''

    // If user clicks a different percentage, recalculate
    gratuity

    public function click(event:Object):Void

    {

    switch (event.target) {

    case percentRadio1:

    calculate();

    break;

    }



    switch (event.target) {

    case percentRadio24:

    calculatesemi();

    break;

    }

    }

    }









    Setting up a Weekly listings/archives

    I'me creating a small classified section where people can
    register and post

    items for sale. The two thinks I need to do, and don't know
    how, is:



    1. Have active listings only show for one week on the
    classified page, and

    then..

    2. Move the listings to an archive page that has links for
    each week of

    listings.



    This sounds out of my league. Any thoughts on how to set this
    up in

    dreamweaver and Access using ASP vbscript?



    Thanks.





    Spry Tabbed Panels and ASP Data

    If I use a Spry Tabbed Panel, is there any benefit to using
    XML data (via

    AJAX) instead of ASP Response.Write data from a recordset.



    --

    Brandon


    http://www.presentationsdirect.com



    Spry Tabbed Panels and ASP Data
    No. What a lot of people don't understand about most Ajax

    implementations is that the entire xml file is downloaded -
    but only

    accessible (and usable) if script is enabled. Using a
    database in most

    cases is the more accessible and efficient method of the two.
    Ajax is

    best used for data processing forms, for example, where it is
    not

    responsible for content that should be accessible and
    indexable.





    --

    Al Sparber - PVII


    http://www.projectseven.com

    Extending Dreamweaver - Nav Systems | Galleries | Widgets

    Authors: ''42nd Street: Mastering the Art of CSS Design''









    ''Brandon'' %26lt;bsmith@presentationsdirect.nospam.com%26gt; wrote
    in message

    news:f1nrva$uv$1@forums.macromedia.com...

    %26gt; If I use a Spry Tabbed Panel, is there any benefit to
    using XML data

    %26gt; (via AJAX) instead of ASP Response.Write data from a
    recordset.

    %26gt;

    %26gt; --

    %26gt; Brandon

    %26gt;
    http://www.presentationsdirect.com

    %26gt;



    IE7 Makes Navigation not show

    Any ideas why the navigation doesn't show on this site in IE7
    until one of

    the navigation links is clicked?




    http://dynamicrenovation.net/



    Thanks



    Travis





  • girl lipstick
  •