caterpillar
08-03-2006, 03:01 AM
Hi all,
i have made a SEARCH page with the following inputs:
KEY
WARD
BLOCK
ZONE
TITLE
SUBT
*All fields are VARCHAR TYPE.
I need to make a query such that whenever the user enters data, result comes, be it 1 input, all inputs or combination of inputs.
This is working in all input fields, except for KEY & WARD. They are showing all records & not filtering as what is being selected.
The query is written below, plz. suggest me something.
-- shows comment
SELECT DISTINCT
FROM blah blah blah................
WHERE
--CONTAINS(viewname.*,@SKey)
(
(c.block LIKE '%' + @SKey +'%') or (c.zone LIKE '%' + @SKey +'%')
)
or
-- CONTAINS (c.*, '*@ward*')
((c.ward = @ward) or (ward <> ''))
--- (c.ward LIKE '%' + @ward +'%')
AND
-- (@block = '') OR (c.block LIKE '%' + @block +'%')
--(c.block = @block )
(c.block LIKE '%' + @block +'%')
--AND ((@zone = '') OR (c.zone = @zone)
AND( c.zone LIKE '%' + @zone +'%')
-- or (@zone = '')
--AND ((@title = '') OR ( c.co_title = @title)
AND (c.title LIKE '%' + @title +'%')
-- or (@title = '')
--AND ((@subt = '') OR (c.co_subt = @subt)
AND (c.subt LIKE '%' + @subt +'%')
--or (@subt = '')
I feel i need to place the ORs and ANDs properly.
Plz. help me out!
Regards
Monica
i have made a SEARCH page with the following inputs:
KEY
WARD
BLOCK
ZONE
TITLE
SUBT
*All fields are VARCHAR TYPE.
I need to make a query such that whenever the user enters data, result comes, be it 1 input, all inputs or combination of inputs.
This is working in all input fields, except for KEY & WARD. They are showing all records & not filtering as what is being selected.
The query is written below, plz. suggest me something.
-- shows comment
SELECT DISTINCT
FROM blah blah blah................
WHERE
--CONTAINS(viewname.*,@SKey)
(
(c.block LIKE '%' + @SKey +'%') or (c.zone LIKE '%' + @SKey +'%')
)
or
-- CONTAINS (c.*, '*@ward*')
((c.ward = @ward) or (ward <> ''))
--- (c.ward LIKE '%' + @ward +'%')
AND
-- (@block = '') OR (c.block LIKE '%' + @block +'%')
--(c.block = @block )
(c.block LIKE '%' + @block +'%')
--AND ((@zone = '') OR (c.zone = @zone)
AND( c.zone LIKE '%' + @zone +'%')
-- or (@zone = '')
--AND ((@title = '') OR ( c.co_title = @title)
AND (c.title LIKE '%' + @title +'%')
-- or (@title = '')
--AND ((@subt = '') OR (c.co_subt = @subt)
AND (c.subt LIKE '%' + @subt +'%')
--or (@subt = '')
I feel i need to place the ORs and ANDs properly.
Plz. help me out!
Regards
Monica