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.
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 guyshelp me what i am doing wrong..Dim sql As StringDim sqlwhere As String = ""sql = "select * from tblMovies WHERE "If Me.cboField1.SelectedValue <> "" And Me.txtValue1.Text <> "" ThenIf Me.cboField1.SelectedValue = Me.txtValue1.Text Thensqlwhere = Me.cboField1.SelectedValue & " = '" & Me.txtValue1.Text & "'"End IfIf Me.cboField1.SelectedValue < Me.txtValue1.Text Thensqlwhere = Me.cboField1.SelectedValue & " < '" & Me.txtValue1.Text & "'"End IfIf Me.cboField1.SelectedValue > Me.txtValue1.Text Thensqlwhere = Me.cboField1.SelectedValue & " > '" & Me.txtValue1.Text & "'"End IfThanks |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-08-23 : 01:07:08
|
[code]Dim sql As StringDim 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 Ifend ifSQL = SQL & sqlwhere[/code]Peter LarssonHelsingborg, Sweden |
 |
|
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 |
 |
|
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 thisIf 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 AthalyeIndia."Nothing is Impossible" |
 |
|
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 |
 |
|
|
|
|