Skip to main content
Known Participant
August 28, 2009
Question

SQL Like and Access database

  • August 28, 2009
  • 3 replies
  • 2308 views

i have to retrieve data from access based on Emp_ID extracted from Sql DB. the queries looks like the following:

Can i do 3 queries and do something like the following:

<cfquery datasource="MasterSQL" username="***" password="***" name="SQLQRY">
     Select Employee.Emp_Name, Salary.Emp_ID
     From Employee inner join Salary on (Employee.Emp_ID = Salary.Emp_ID) AND (Employee.SectionName = Salary.SectionName)
     Where Emp_Name like <cfqueryparam value="%#arguments.search#%" cfsqltype="Sql_VarChar">
</cfquery>

<cfquery datasource="MasterDB" name="AccessQRY">
     Select Emp_Pro.Emp_ID
     From Emp_Pro
     WHERE Emp_Pro.Emp_ID like ("%#ValueList(SQLQRY.Emp_ID)#%")
</cfquery>

<cfquery datasource="MasterDB" name="AccessQRY2">
     Select Emp_Info.Desc,
     From Emp_Info inner join Emp_Pro on (Emp_Info.Emp_ID = Emp_Pro.Emp_ID) AND (Emp_Info.Con = Emp_Pro.Con)
     WHERE Emp_Info.Emp_ID IN

this block will change too...
( <cfqueryparam
value="#ValueList(SQLQRY.Emp_ID)#"
cfsqltype="cf_sql_integer"
list="true">
)

</cfquery>
What do i have to change to make this query work...
    This topic has been closed for replies.

    3 replies

    Inspiring
    September 2, 2009

    CAn you export data from Access as csv? If you can you can easily import data from Access to MySQL!!

    Just type this code to your mysql query browser and execute operation:

    load data local infile 'C:\yourfile.csv' into table yourtable
    fields terminated by ','
    enclosed by '"'
    lines terminated by ' '
    (column1,column2,column3,column4,column5)

    Note that columns names in csv must be same as columns names in MySQL database.
    Also you must have same number of columns.

    Inspiring
    August 28, 2009

    This is the correct syntax:

    WHERE Emp_ID LIKE "%#SQLQRY.Emp_ID#%"

    or if you prefer more

    WHERE Emp_Pro.Emp_ID LIKE "%#SQLQRY.Emp_ID#%"

    RosieGpAuthor
    Known Participant
    August 28, 2009

    The firts query returns me an ID

    A 1000

    but the second query  won't match any ID

    it should retun 1000** right ???


    The Emp_ID from the first query (Sql Server)looks like the following:
    A 1000
    A 1123
    A 23456
    B 450674

    The Emp_ID in Access DB looks like
    1000**
    1123***
    23456**
    450674***

    If i just use WHERE IN it doesn't return anything so I have to use LIKE some how to match these Emp_ID...

    That is what I was trying to do here in second query use like and extract the Emp_ID from Access DB to pass in the 3rd query to reterive Emp_Desc in the 3rd query...

    Any help is appreciated...

    Inspiring
    August 28, 2009

    This line looks like a huge problem:

    WHERE Emp_Pro.Emp_ID like ("%#ValueList(SQLQRY.Emp_ID)#%")

    why do you have "like" instead of "in" ?

    RosieGpAuthor
    Known Participant
    August 28, 2009

    i donot know what to put there exactly, I don't know the right syntax...

    may be it is more like

    WHERE Emp_Pro.Emp_ID like ("%#SQLQRY.Emp_ID#%")

    need help determining the right syntax for this query...