Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 25th, 2007, 06:15 PM
Authorized User
Points: 245, Level: 4
Points: 245, Level: 4 Points: 245, Level: 4 Points: 245, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: Houston, TX, USA.
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to ricespn
Default Construct a SQL Select Statement

Hi guys,

I'm trying to construct a Select statement according to the values of 4 boxes, but is getting kinda complicated. Any help I'll appreciate it.

here's what I have so far:

sSQL = "Select * from mytable "

If txtMemberNumber.Text <> "" Then
sSQL = sSQL + "WHERE field1 like '%" + txtMemberNumber.Text + "'"
End If

If txtMemberName.Text <> "" And txtMemberNumber.Text <> "" Then
    sSQL = sSQL + "and field2 like '%" + txtMemberName.Text + "%'"
Else
    sSQL = sSQL + "WHERE field2 like '%" + txtMemberName.Text + "%'"
End If

If txtMemberLastName.Text <> "" And txtMemberName.Text <> "" And txtMemberNumber.Text <> "" Then
    sSQL = sSQL + "and field3 like '%" + txtMemberLastName.Text + "%'"
Else
    sSQL = sSQL + "WHERE field3 like '%" + txtMemberLastName.Text + "%'"
End If

If txtMemberSSN.Text <> "" And txtMemberLastName.Text <> "" And txtMemberName.Text <> "" And txtMemberNumber.Text <> "" Then
sSQL = sSQL + "and field4 like '%" + txtMemberSSN.Text + "%'"
Else
    sSQL = sSQL + "WHERE field4 like '%" + txtMemberSSN.Text + "%'"
End If


=======================
Strange and crazy, but everything is possible
__________________
=======================
Strange and crazy, but everything is possible
Reply With Quote
  #2 (permalink)  
Old May 28th, 2007, 07:57 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

you didn't specify a problem...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select from another select statement to a repeater simsen ASP.NET 2.0 Professional 0 May 2nd, 2007 04:34 PM
SQL select statement problem shrisangeeta Classic ASP Databases 3 June 15th, 2006 10:28 AM
YYYY and MM in access' SQL select statement Condor76 Access VBA 1 February 15th, 2006 02:47 PM
help needed with a SQL select statement problem wslyhbb Java Databases 1 August 14th, 2003 07:30 AM
ASP sql select statement scorpio Classic ASP Databases 5 July 30th, 2003 06:48 AM



All times are GMT -4. The time now is 04:11 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.