Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Search Criteria

Author  Topic 

saidev
Posting Yak Master

101 Posts

Posted - 2006-08-22 : 13:52:43
Hi Guys,

I have two drop down boxes and one text box. Text box is the value to search.


1st drop down is the value i select and second drop down is " =, <, >, > =, < = ".

if i select " =" then i am getting the right value but if i select " < " then it is picking up only " > " .Here is my code. can you guys
help me what i am doing wrong..



Dim sql As String
Dim sqlwhere As String = ""

sql = "select * from tblMovies WHERE "
If Me.cboField1.SelectedValue <> "" And Me.txtValue1.Text <> "" Then

If Me.cboField1.SelectedValue = Me.txtValue1.Text Then

sqlwhere = Me.cboField1.SelectedValue & " = '" & Me.txtValue1.Text & "'"
End If

If Me.cboField1.SelectedValue < Me.txtValue1.Text Then
sqlwhere = Me.cboField1.SelectedValue & " < '" & Me.txtValue1.Text & "'"
End If

If Me.cboField1.SelectedValue > Me.txtValue1.Text Then
sqlwhere = Me.cboField1.SelectedValue & " > '" & Me.txtValue1.Text & "'"
End If

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-08-23 : 01:07:08
[code]Dim sql As String
Dim sqlwhere As String = ""

sql = "select * from tblMovies WHERE "
If Me.cboField1.SelectedValue <> "" And Me.txtValue1.Text <> "" Then
If Me.cboField1.SelectedValue = Me.txtValue1.Text Then
sqlwhere = Me.cboField1.SelectedValue & " = '" & Me.txtValue1.Text & "'"
End If

If Me.cboField1.SelectedValue < Me.txtValue1.Text Then
sqlwhere = Me.cboField1.SelectedValue & " < '" & Me.txtValue1.Text & "'"
End If

If Me.cboField1.SelectedValue > Me.txtValue1.Text Then
sqlwhere = Me.cboField1.SelectedValue & " > '" & Me.txtValue1.Text & "'"
End If
end if

SQL = SQL & sqlwhere[/code]
Peter Larsson
Helsingborg, Sweden
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-08-23 : 02:10:33
if the value which you are comparing are numbers then i guess you need to convert them to int and then compare.

If CInt(Me.cboField1.SelectedValue) < CInt(Me.txtValue1.Text) Then
sqlwhere = Me.cboField1.SelectedValue & " < '" & Me.txtValue1.Text & "'"
End If

If CInt(Me.cboField1.SelectedValue) > CInt(Me.txtValue1.Text) Then
sqlwhere = Me.cboField1.SelectedValue & " > '" & Me.txtValue1.Text & "'"
End If


Chirag
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-08-23 : 04:00:59
quote:
Originally posted by chiragkhabaria

if the value which you are comparing are numbers then i guess you need to convert them to int and then compare.



If the values which are getting compared are integer, why should you put quotes around it...it will like this

If CInt(Me.cboField1.SelectedValue) < CInt(Me.txtValue1.Text) Then
sqlwhere = Me.cboField1.SelectedValue & " < " & Me.txtValue1.Text
End If

If CInt(Me.cboField1.SelectedValue) > CInt(Me.txtValue1.Text) Then
sqlwhere = Me.cboField1.SelectedValue & " > " & Me.txtValue1.Text
End If


Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-08-23 : 04:18:17
quote:

If the values which are getting compared are integer, why should you put quotes around it...it will like this



Aha i never looked into the where part, i was talking about VB code, so just suggest CInt for conversion to integer and then compare.

Chirag
Go to Top of Page
   

- Advertisement -