DPChallenge: A Digital Photography Contest You are not logged in. (log in or register
 

DPChallenge Forums >> General Discussion >> Question for SQL Programmers
Pages:  
Showing posts 1 - 8 of 8, (reverse)
AuthorThread
06/19/2007 02:31:47 PM · #1
Hi - Can anyone help..

I have a web page that query a SQL server - one database called MasterTable

on the web page is 5 text boxes, (each one will query a field on the database)

the user will enter a word in the text box and it would query the database and pull the results which is then displayed...

I can do this if the user enters text into all 5 boxes using the AND command.. Easy...

but can't think how its done if the text box is empty.. as if the user has entered text in to text box 2 and 4 only .....

any ideas?
06/19/2007 02:36:04 PM · #2
You could check the value of the box such as and this is not in PHP or Perl but you should be able to figure it out.

If Box5.Value = nil then

and then make a statment to deal with it by only using a 4 field query. Basicly what your doing is checking the value of the fields using whatever the scripting language is before performing the SQl query.

Message edited by author 2007-06-19 14:37:19.
06/19/2007 02:56:42 PM · #3
Here is the logic -

Assuming the field names of the table are field1 thru field5.

String whereClause = empty string;
if (box1.value is not empty) then
if (whereClause is not empty) then
whereClause = whereClause + " AND ";
end if;
whereClause = whereClause + " field1 = " + box1.value ;
end if;

Use the above IF condition for all the 5 boxes/fields. I.e. for box2/field2 the IF condition would be -

if (box2.value is not empty) then
if (whereClause is not empty) then
whereClause = whereClause + " AND ";
end if;
whereClause = whereClause + " field2 = " + box2.value ;
end if;

Finally, the variable "whereClause" will have the value which you can use in the WHERE condition of your SQL.

06/19/2007 03:03:05 PM · #4
Hi Dantis / Jeffrey

Many many thanks for pointing me in the right direction

Just learning SQl and Visual Studio -

Tony ;-)

06/19/2007 03:03:10 PM · #5
What language do you use on your webpage and what SQL-server?

Edit: you post during my post! Understand your environment. (I'm more a PHP man)

Message edited by author 2007-06-19 15:05:18.
06/19/2007 03:24:27 PM · #6
One common method for things like this is similar to this

SELECT somevalues FROM yourtable
WHERE (columna LIKE 'searchvalue' or searchvalue IS NULL)
AND (columnb LIKE 'searchvalue2' or searchvalue2 IS NULL)

and so on.

Obviously you'd need to create the SQL string properly. ;)

Also if you're not passing through NULLs or you're passsing empty strings etc. change the OR clause appropriately.

Oh, and clean your data before using it if using values input from a web page.

Message edited by author 2007-06-19 15:25:43.
06/19/2007 03:41:18 PM · #7
Originally posted by hajeka:

What language do you use on your webpage and what SQL-server?

Edit: you post during my post! Understand your environment. (I'm more a PHP man)


Hi - Using SQL Server 2000 and Language will be C++ but i'm going on a .net course soon so Looking forward to that

T
06/19/2007 03:51:15 PM · #8
Originally posted by agwright:

Originally posted by hajeka:

What language do you use on your webpage and what SQL-server?

Edit: you post during my post! Understand your environment. (I'm more a PHP man)


Hi - Using SQL Server 2000 and Language will be C++ but i'm going on a .net course soon so Looking forward to that

T


ASP - Active Server Pages im guessing, I believe you can sue Visual Basic or Visual C++ for those. Never used them im on a linux server.
Pages:  
Current Server Time: 03/29/2024 03:41:16 AM

Please log in or register to post to the forums.


Home - Challenges - Community - League - Photos - Cameras - Lenses - Learn - Prints! - Help - Terms of Use - Privacy - Top ^
DPChallenge, and website content and design, Copyright © 2001-2024 Challenging Technologies, LLC.
All digital photo copyrights belong to the photographers and may not be used without permission.
Current Server Time: 03/29/2024 03:41:16 AM EDT.