473,508 Members | 2,091 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Query Error ( 2 field values into 1 Query )

Fary4u
273 Contributor
Hi

i'm trying to figer it out how to do take 2 value from table & set into SQL Query

i've got database table with name " TABLE -> PRODUCT" & " FIELD -> TYPE "

here is the code

res = Request.form("res")
res2 = Request.form("res2")

chkres = " and products.type = '" &res&"'"
chkres2 = " and products.type = '" &res2&"'"

strchk = " chkres & chkres2 "

sqlText = "select distinct(products.productID), "
sqlText = sqlText & "products.producttype "
sqlText = sqlText & str1 & str2 & strchk

some thing like this how can i take 2 value & execute this.

Thanks in advance
Fary
Sep 2 '08 #1
3 2070
Fary4u
273 Contributor
Is that possible we take 2 or 3 true values from 1 DB Field ?
& Run with SQL Query ?
Here is the complete code
[PHP]
<%
( in Database Filed as a Type - Residential, Commerical or Other )
chkres = Request.form("chkres") ' Resident Checkbox
chkcom = Request.form("chkcom") ' Commercial Checkbox
chkoth = Request.form("chkoth") ' Other Checkbox

( in Database Category_ID - Sale or Tolet )
strCat = Request.form("strCat") ' Category Radio Button

if chkres = "yes" then
chkres = "Residential"
end if
if chkcom = "yes" then
chkcom = "Commercial"
end if
if chkoth = "yes" then
chkoth = "Others"
end if

strCatWhere = " and property.category_ID = '" &strCat&"'"

strChk1 = " and property.Type = '" &chkres&"'" ' Check box options
strChk2 = " and property.Type = '" &chkcom&"'" ' Check box options
strChk3 = " and property.Type = '" &chkoth&"'" ' Check box options
strchk = strChk1 & strChk2 & strChk3


set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConString

sqlText = "select distinct(property.property_ID), "
sqlText = sqlText & "Property.Image ,"
sqlText = sqlText & "Property.Type, "
sqlText = sqlText & "Property.price "
sqlText = sqlText & "from property "
sqlText = sqlText & "where property.property_ID = "
sqlText = sqlText & "property.property_ID"
sqlText = sqlText & strCatWhere & strchk '( strChk1 or strChk2 strChk3)
%>
[/PHP]
Sep 3 '08 #2
Fary4u
273 Contributor
is that possible take 2 value from table filed & set into SQL Query
i've got database table with name " TABLE -> PROPERTY" & " FIELD -> TYPE " holding value with following:

in Database Filed as a Type - Residential, Commerical or Other
in Database Property_ID - Sale or Tolet

& Run with SQL Query ?
Here is the complete code
[PHP]
<%
( in Database Filed as a Type - Residential, Commerical or Other )
chkres = Request.form("chkres") ' Resident Checkbox
chkcom = Request.form("chkcom") ' Commercial Checkbox
chkoth = Request.form("chkoth") ' Other Checkbox

( in Database Property_ID - Sale or Tolet )
strCat = Request.form("strCat") ' Category Radio Button

if chkres = "yes" then
chkres = "Residential"
end if
if chkcom = "yes" then
chkcom = "Commercial"
end if
if chkoth = "yes" then
chkoth = "Others"
end if

strCatWhere = " and property.category_ID = '" &strCat&"'"

strChk1 = " and property.Type = '" &chkres&"'" ' Check box options
strChk2 = " and property.Type = '" &chkcom&"'" ' Check box options
strChk3 = " and property.Type = '" &chkoth&"'" ' Check box options
strchk = strChk1 & strChk2 & strChk3


set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConString

sqlText = "select distinct(property.property_ID), "
sqlText = sqlText & "Property.Type "
sqlText = sqlText & "from property "
sqlText = sqlText & "where property.property_ID = "
sqlText = sqlText & "property.property_ID"
sqlText = sqlText & strCatWhere & strchk '( strChk1 or strChk2 strChk3)
%>
[/PHP]
line 22 with OR is work fine but i need to including every thing.
[php]
strChk1 = " and property.Type = '" &chkres&"'" ' Check box options
strChk2 = " or property.Type = '" &chkcom&"'" ' Check box options
strChk3 = " or property.Type = '" &chkoth&"'" ' Check box options
strchk = strChk1 & strChk2 & strChk3
[/php]
Sep 3 '08 #3
jhardman
3,406 Recognized Expert Specialist
are the two always going to be in the same order? if so, you could say:
Expand|Select|Wrap|Line Numbers
  1. "SELECT * FROM products WHERE type LIKE '%" & res & "%" & res2 & "%'"
If not, you could say,
Expand|Select|Wrap|Line Numbers
  1. "SELECT * FROM products WHERE type LIKE '%" & res & "%" & res2 & "%' OR type LIKE '%" & res2 & "%" & res & "%'"
Let me know if this helps.

Jared
Sep 4 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2085
by: Dalan | last post by:
I can't seem to find a workaround of Query Syntax Error. Actually, the query performs just fine, except when the last record on a related subform is deleted, then it generates a Runtime Error 3075...
1
1622
by: James Armstrong | last post by:
Hello all - Hopefully there's a quick answer to this one, but I haven't found any good info in my reference books... I have a list of customers and a list of prospective customers. All I care...
1
682
by: bdt513 | last post by:
I am trying to extract the values from a query using VBA. Specifically, I want to concatenate all the values of the "rosEmail" field from query "qselRosterEmailList" into one string (strEmails). I...
1
1816
by: j.t.w | last post by:
Hi. I'm new to ASP.Net and I'm running into a simple problem (I think). I'm trying to get 2 values from 2 separate queries into 2 different variables. I would then like to take the difference...
3
30269
by: mkjets | last post by:
I have worked for hours on trying to find a solution and have not figured it out. I am working in Access 2003. I need to create a query that takes values from 1 table and displays them in...
5
2327
by: sklett | last post by:
I'm not real experienced with asp.net so this may be obvious. I've got a situation where some of my client side javascript is causing my posted form's controls to lose their values. In other...
10
7939
by: rousseaud | last post by:
Hello- I'm having a little trouble. I want to create a query that will return the most recent records (by date) for all unique values in a certain field in the query. I'll be pulling data from 3...
2
1533
by: JC2710 | last post by:
Hi I would like a Query that Updates a field to indicate that records have a duplicate entry( records with same values). My table is ..... Code........Process..........Quantity ...
4
7586
by: franc sutherland | last post by:
Hello, I am using Access 2003. I am having trouble trapping the "can't append all the records in the append query" error message when appending data to a query from a table which is linked to...
1
1711
by: TZEM | last post by:
Hi - I'm new to Access and trying to create a complicated database that records info about system interfaces. I want to create a crosstab query that returns a field from the interface record, if a...
0
7124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.