Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

cfquery update if data exists in second table, otherwise insert

Avatar of armanbena
armanbena asked on
ColdFusion LanguageSQL
4 Comments1 Solution613 ViewsLast Modified:
Hi all,

I am working on creating a cfquery to update data from a form if there is a record in a second table that already exists, otherwise insert.  I think I'm thinking more in terms of sql server and creating a stored procedure, but do not know of proper syntax in setting up a cfquery on page.
This is what I have:
<cfquery name="qUpdateData" datasource="ybgmaster">

DECLARE @review_id int

DECLARE @presale_id int

 

select @review_id = #url.id#

from tbl_DNOA_Review_MA

where d_id = #url.id#

 

if @review_id = #url.id#

begin

 

 

                                    UPDATE tbl_DNOA_Review_MA as a

                                     set DNoA_Administer='#form.administer#',

                                                 DNoA_Comments='#form.DNoA_comments#',

                                                 other_Reason='#form.other_reason#'

                                                 where a.d_id=#url.id#;

                                                 

else

begin

INSERT INTO tbl_DNOA_Review_MA

(

d_id,

DNoA_Administer,

DNoA_Comments,

other_Reason,

DNoA_Reviewer,

date_Reviewed)

 

VALUES

(

#url.id#,

'#form.administer#',

'#form.DNoA_comments#',

'#form.other_reason#',

'#form.DNoA_Reviewer#',

<cfqueryparam value="#form.date_Reviewed#" cfsqltype="cf_sql_timestamp">

);

end

</cfquery>
ASKER CERTIFIED SOLUTION
Avatar of armanbena
armanbena

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answers