ostashenp
asked on
Insert Statement with Coldfusion based on a previous query
Here is my problem:
I am trying to do an insert query based on information queried in a previous statement. I am doing a query to see if the client exists, if it does then it should proceed to the next insert, if the client does not exist it should input the information then proceed with the next insert. Here is my code for it.
<THIS PART QUERIES THE FIELD I WANT TO CHECK>
<cfquery name="getClients" datasource="test" dbtype="test">
select Company
from Clients
</cfquery>
<THIS IS SUPPOSED TO CHECK TO SEE IF THERE IS AN ENTRY FOR THE ABOVE FIELD>
<CFIF #ParameterExists(getClient s.Company) # is "No">
<cfquery name="insertCompany" datasource="test" dbtype="test">
INSERT INTO Clients
(City,Company,CTDue,CTPack age,CTR,CT Renewed,CT Vis,DateCr eated,Date Mod,ID,Log in,OSJ,OSR ,Password, Referred,S tate,TimeC reated,Tim eMod,Singl e,CBIA)
VALUUES('#City#','#Company #','#CTDue #','#CTPac kage#','#C TP#','#CTR enewed#',' #CTVis#',' #DateCreat ed#','#Dat eMod#','#J obnumber#' ,'#Login#' ,'#OSJ#',' #OSR#','#P asswaord#' ,'#Referre d#','#Stat e#','#Time Created#', '#TimeMod# ','#Single #','#CBIA# ')
</cfquery>
</cfif>
<THIS PART BELOW WORKS >
<CFQUERY name="insertJobs" DATASOURCE="test" datatype="test">
INSERT INTO JOBS (CBia,Company,jobnumber,Ci ty,State,l ocation,Jo bTitle,top url,JobFie ld2,Joblis ting,Count y,login,pw ,single,da teentered, timeentere d,Moddate, Modtime,eR esumes,sen d_resumes, exp_date,t opusa)
VALUES ('#CBia#','#Company#','#jo bnumber#', '#location #','#state #','#locat ion#','#Jo bTitle#',' #website#' ,'#jobfiel d2#','#Job listing#', '#ValueLis t(getCount ies.Counti es)#','#lo gin#','#pw #','#singl e#',#datee ntered#,#t imeentered #,#Moddate #,#Modtime #,'#eResum es#','#sen d_resumes# ',#exp_dat e#,'1')
</CFQUERY>
I am trying to do an insert query based on information queried in a previous statement. I am doing a query to see if the client exists, if it does then it should proceed to the next insert, if the client does not exist it should input the information then proceed with the next insert. Here is my code for it.
<THIS PART QUERIES THE FIELD I WANT TO CHECK>
<cfquery name="getClients" datasource="test" dbtype="test">
select Company
from Clients
</cfquery>
<THIS IS SUPPOSED TO CHECK TO SEE IF THERE IS AN ENTRY FOR THE ABOVE FIELD>
<CFIF #ParameterExists(getClient
<cfquery name="insertCompany" datasource="test" dbtype="test">
INSERT INTO Clients
(City,Company,CTDue,CTPack
VALUUES('#City#','#Company
</cfquery>
</cfif>
<THIS PART BELOW WORKS >
<CFQUERY name="insertJobs" DATASOURCE="test" datatype="test">
INSERT INTO JOBS (CBia,Company,jobnumber,Ci
VALUES ('#CBia#','#Company#','#jo
</CFQUERY>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I got that but now im getting an error on the data entry:
Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Line 3: Incorrect syntax near '2007'.
The error occurred in D:\Inetpub\test\get_jobs.c fm: line 89
87 : INSERT INTO Clients
88 : (City,Company,CTDue,CTPack age,CTR,CT Renewed,CT Vis,DateCr eated,Date Mod,ID,Log in,OSJ,OSR ,Password, Referred,S tate,TimeC reated,Tim eMod,Singl e,CBIA)
89 : VALUES('#Location#','#Comp any#','#CT Due#','#CT Package#', '#CTR#','# CTRenewed# ','#CTVis# ','#dateen tered#','# Moddate#', '#Jobnumbe r#','#Logi n#','#OSJ# ','#OSR#', '#PW#','#R eferred#', '#State#', '#timeente red#','#Mo dtime#','# Single#',' #CBIA#')
90 : </cfquery>
91 : </cfif>
SQL INSERT INTO Clients (City,Company,CTDue,CTPack age,CTR,CT Renewed,CT Vis,DateCr eated,Date Mod,ID,Log in,OSJ,OSR ,Password, Referred,S tate,TimeC reated,Tim eMod,Singl e,CBIA) VALUES('Houston','Alpha Synopsys Inc','{d '2007-04-29'}','30','N','{ d '2007-04-28'}','Y','{d '2007-03-30'}','{d '2007-03-30'}','J16996','l ogin','Y', 'N','ocjob s','','Tex as','{t '05:38:57'}','{t '05:38:57'}','J','N')
DATASOURCE test
VENDORERRORCODE 170
SQLSTATE HY000
Resources:
* Check the ColdFusion documentation to verify that you are using the correct syntax.
* Search the Knowledge Base to find a solution to your problem.
Error Executing Database Query.
[Macromedia][SQLServer JDBC Driver][SQLServer]Line 3: Incorrect syntax near '2007'.
The error occurred in D:\Inetpub\test\get_jobs.c
87 : INSERT INTO Clients
88 : (City,Company,CTDue,CTPack
89 : VALUES('#Location#','#Comp
90 : </cfquery>
91 : </cfif>
SQL INSERT INTO Clients (City,Company,CTDue,CTPack
DATASOURCE test
VENDORERRORCODE 170
SQLSTATE HY000
Resources:
* Check the ColdFusion documentation to verify that you are using the correct syntax.
* Search the Knowledge Base to find a solution to your problem.
Your date/time values should not be in quotes...
Use
#ModDate#
or
#createODBCdate(ModDate)#
You have them as '#ModDate#'
ASKER