populating dropdown using tables from two databases

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

  1. #1

    Default populating dropdown using tables from two databases

    I tried it with populating the values from the first qury to an array and using
    that array inside

    NOT IN clause of second query. But its giving error
    I am using Coldfusion 5.0 with SQL Server-2000


    ************************************************** ******************************
    *********************

    *************************************

    <CFQUERY NAME ="UserExists"
    PASSWORD="#Request.DataSources.FirstDB.DBPassword# "

    USERNAME="#Request.DataSources.FirstDB.DBUserName# "

    DATASOURCE="#Request.DataSources.FirstDB.DSN#"

    DBTYPE="#Request.DataSources.FirstDB.ConnectionTyp e#">
    SELECT UserID
    FROM Signatorie
    </CFQUERY>

    <CFSET UserArray = ArrayNew(1)>
    <CFLOOP query="UserExists" >
    <CFSET UserArray[CurrentRow[1]] = #UserID#>
    </CFLOOP>

    <CFQUERY NAME="GetUsers" PASSWORD="#Request.DataSources.SecondDB.DBPassword #"

    USERNAME="#Request.DataSources.Syn_Security.DBUser Name#"

    DATASOURCE="#Request.DataSources.SecondDB.DSN#"

    DBTYPE="#Request.DataSources.SecondDB.ConnectionTy pe#">
    SELECT UserID, UserName
    FROM Users
    WHERE UserID NOT IN(#UserExists#)
    </CFQUERY>

    ************************************************** ******************************
    *********************

    *************************************Error:
    Expression result cannot be converted to a string

    Expressions used inside tags like CFOUTPUT, CFQUERY, CFMAIL, etc. must
    evaluate to a value

    that can be converted to a string for output or dynamic text accumulation
    purposes. Complex

    objects, such as queries, arrays, and COM/DCOM objects, cannot be represented
    as strings.

    ************************************************** ******************************
    *********************

    *************************************
    Is there any way to solve this pblm
    Thanks


    cfdyn Guest

  2. Similar Questions and Discussions

    1. tables vs databases
      This is probably a stupid question but is how is there much of a difference in performance in storing all tables in the one database and spreading...
    2. Slow populating dropdown?
      I am, for the first time, using Dreamweaver to create recordsets and populate a few dropdowns. Normally, I'd do this by hand, but thought I'd give...
    3. Dropdown question (populating a text field)
      Hello everybody, I have a problem and would appreciate any help on offer. I have a table with two fields in it. On my form there are the...
    4. Joining Tables Across Databases
      This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ...
    5. Populating DropDown in webform
      #1) put the data in table AA and put a flag like "New Detail" yes,no and requery you database and if user has selected "New Detail" then add ther...
  3. #2

    Default Re: populating dropdown using tables from two databases

    Hi cfdyn

    At the moment you are trying to compare a UserID to a query object - this
    isnt' possible. You need to make the results of the query into a list of values
    before you can use it in the query.

    See attached code.

    Zoe

    <CFQUERY NAME="GetUsers">
    SELECT UserID, UserName
    FROM Users
    WHERE UserID NOT IN(#ValueList(UserExists.UserID)#)
    </CFQUERY>

    zoeski80 Guest

  4. #3

    Default Re: populating dropdown using tables from two databases

    A good suggestion, but before that, I'd try and connect the two databases on
    the server side. I'm not a SQL Server guy, so I'm not sure of the syntax, but
    I know this is possible:

    select UserID, UserName
    from db2.Users
    where UserID not in (select UserID from db1.Signatorie)

    That'll save you some work on the CF side, and of course transfering the data
    twice. Let the DB do what it's good at. Even if your DB's are on different
    servers, this should still be possible.

    JR


    jonwrob Guest

  5. #4

    Default Re: populating dropdown using tables from two databases

    I agree with jonwrob. I do it all the time.

    -- same server syntax
    from database.owner.object_name .

    -- linked server syntax
    from linked_server.catalog.schema.object

    mxstu Guest

  6. #5

    Default Re: populating dropdown using tables from two databases

    Thank You zoeski80, it works fine..
    but the sql server query syntax is not working
    suppose my owner name is slpy/admin and database name seconddb what exactly should I writeText
    cfdyn Guest

  7. #6

    Default Re: populating dropdown using tables from two databases

    yeah got the correct syntax, but now its giving 'Permission' Error
    cfdyn Guest

  8. #7

    Default Re: populating dropdown using tables from two databases

    I'm not sure which database is which, but make sure the datasource you use is
    logged in as a user that has permissions to both database objects. For example:


    firstDatasource
    ======================
    user name: sa
    database: firstDatabase
    * "sa" has permissions for tables in both databases

    Note: Using the "sa" login is not recommended. This is just an example

    secondDatasource
    ======================
    user name: otherSQLUser
    database: secondDatabase
    * "otherSQLUser" only has permissions for tables in "secondDatabase"




    This query would work

    <cfquery name="test" datasource="firstDatasource">
    SELECT UserID, UserName
    FROM secondDatabase.otherSQLUser.Users
    WHERE UserID NOT IN (
    SELECT UserID
    FROM firstDatabase.dbo.Signatorie
    )
    </cfquery>

    .... but this query would fail because the "otherSQLUser" has no permissions
    to table "Signatorie" ...

    <cfquery name="test" datasource="secondDatasource">
    SELECT UserID, UserName
    FROM secondDatabase.otherSQLUser.Users
    WHERE UserID NOT IN (
    SELECT UserID
    FROM firstDatabase.dbo.Signatorie
    )
    </cfquery>

    mxstu 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