Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: examples of a dynamic query


Message #1 by Leo Clayton <claytonl@z...> on Tue, 21 Nov 2000 16:34:59 -0500
Can someone please help me with the following:

I have a form that has up to five fields that can have entries in them.  I 

want to be able to UPDATE the relative fields  in a table based upon 

whether or not there is an entry in that particular form field.  What I 

don't know how to do is phrase my UPDATE statement accordingly.



How do you say in SQL (if something is in any of these form fields then SET 

the appropriate table field to what's in the form field WHERE the IDNumber 

(from the table) =  Session("IDNumber")?  Someone told me to do a dynamic 

query (which I don't know how to).  How do I do the above and is a dynamic 

query the right approach?



How will the action page know which of the five have entries in them?



Message #2 by "Ken Schaefer" <ken@a...> on Wed, 22 Nov 2000 18:13:17 +1100
You posted the same question on the Beginning ASP list, and there were two

answers in reply.



Cheers

Ken



----- Original Message -----

From: "Leo Clayton" <claytonl@z...>

To: "ASP Databases" <asp_databases@p...>

Sent: Wednesday, November 22, 2000 8:34 AM

Subject: [asp_databases] examples of a dynamic query





> Can someone please help me with the following:

> I have a form that has up to five fields that can have entries in them.  I

> want to be able to UPDATE the relative fields  in a table based upon

> whether or not there is an entry in that particular form field.  What I

> don't know how to do is phrase my UPDATE statement accordingly.

>

> How do you say in SQL (if something is in any of these form fields then

SET

> the appropriate table field to what's in the form field WHERE the IDNumber

> (from the table) =  Session("IDNumber")?  Someone told me to do a dynamic

> query (which I don't know how to).  How do I do the above and is a dynamic

> query the right approach?

>

> How will the action page know which of the five have entries in them?





Message #3 by dont worry <aspmailbox@y...> on Wed, 22 Nov 2000 07:47:52 -0800 (PST)
Alittle confused but...



<%dim str

str = "UPDATE MYTABLE SET"

If r.f("blah") <> "" THEN

str = str + " thisfield = " &r.f("blah")

elseif r.f("blah2") <> "" THEN..

...

you can try a response.write str to see the

querystring being built.

above example would produce.



UPDATE MYTABLE SET thisfield = blah

where you control thisfield and blah is the value from

the request.form.  

Once you get advanced enough you will KNOW that you

DONT want to use this method.

DW











--- Leo Clayton <claytonl@z...> wrote:

> Can someone please help me with the following:

> I have a form that has up to five fields that can

> have entries in them.  I 

> want to be able to UPDATE the relative fields  in a

> table based upon 

> whether or not there is an entry in that particular

> form field.  What I 

> don't know how to do is phrase my UPDATE statement

> accordingly.

> 

> How do you say in SQL (if something is in any of

> these form fields then SET 

> the appropriate table field to what's in the form

> field WHERE the IDNumber 

> (from the table) =  Session("IDNumber")?  Someone

> told me to do a dynamic 

> query (which I don't know how to).  How do I do the

> above and is a dynamic 

> query the right approach?

> 

> How will the action page know which of the five have

> entries in them?

> 


  Return to Index