Looping a list in SQL 2000 SPROC

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Looping a list in SQL 2000 SPROC

    Hey guys, just trying to learn something new today and wanted to convert one of
    my cf pages to a sproc. This page just sets up security for the application. In
    Coldfusion, all I'm doing is looping over a list.

    The list is generated from a group of checkboxes, and looks like this.

    <cfif isDefined("form.tech")>
    <cfloop index="i" list="#form.tech#">
    <cfquery name="UpdateTech" datasource="#application.dsn#">
    INSERT INTO Q_SecurityUser_TBL
    (Employee_ID, Security_ID, Lob_ID)
    VALUES(<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#i#">, 1,
    <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#Lob_ID#">)
    </cfquery>
    </cfloop>
    </cfif>

    How would I loop over this list in SQL?

    dj shane Guest

  2. Similar Questions and Discussions

    1. Sproc Result as Comma Seperated List
      Hey guys, I had built some photoblogging software in the past and am currently just revising it to bring it up to validated xhtml and running...
    2. parsing and looping over a list
      All, I need to parse a list that looks like this: de={ts '2004-08-06 12:14:00'}|s=title header|entID=15,de={ts '2004-08-06 13:05:00'}|s=title...
    3. looping over a list problem
      I am having a problem looping over a list with some elements that are empty. Here is a sample of the list: address_street=8349+White+Dr custom=...
    4. [PHP] Looping through a list - Newbie question
      There are a lot of methods. The most common is using an array: $_SESSION = Array ("1","2","3","4","5"); foreach($_SESSION as $id) { echo $id; }...
    5. Looping through a list - Newbie question
      explode() and then foreach are your friends :) explode() using the comma as your separator and then traverse the array using foreach. ...
  3. #2

    Default Re: Looping a list in SQL 2000 SPROC

    Hi Shane,
    <cfquery name="UpdateTech" datasource="#application.dsn#">
    INSERT INTO Q_SecurityUser_TBL
    (Employee_ID, Security_ID, Lob_ID)
    VALUES(<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#i#">, 1,
    <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#Lob_ID#">)
    </cfquery>


    It's best to issue as few DB transactions as possible. I'd construct a bulk
    insert string from the list:


    <cfset myquery = "INSERT INTO Q_SecurityUser_TBL
    (Employee_ID, Security_ID, Lob_ID)
    SELECT ">

    <cfloop index="i" list="#form.tech#">
    <cfset myquery = myquery & i &", 1," & lob_id & "UNION SELECT ">
    </cfloop>

    <cfset myquery = mid(myquery,1,len(myquery-13))>

    <cfoutput>#myquery#</cfoutput><!--- to see what the loop constructed --->

    <cfquery name="UpdateTech" datasource="#application.dsn#">
    #myquery#
    </cfquery>

    HTH,

    philh Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139