Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 2nd, 2006, 04:55 PM
Authorized User
 
Join Date: Jul 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL Query problem

Hi all,
i have made a SEARCH page with the following inputs:

KEY
WARD
BLOCK
ZONE
TITLE
SUBT

I need to make a query such that whereever the user enters data, result comes, be it 1 input, all inputs or combination of inputs.
This is working in all ipput 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


 
Old August 2nd, 2006, 06:45 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Hi Monica,

You might already know this. I don't know what the datatype for any of these fields are but if you use LIKE with some kind of number/integer then if you select a 1, the recordset will include any integer that has a 1 in it... and therefore possibly not filter like you want it to.
c.ward will either equal your selected value OR it will pull everyting where its not equal to nothing

So it seems that your ward statement will not filter at all unless there are fields without values.




 
Old August 2nd, 2006, 07:59 PM
Authorized User
 
Join Date: Jul 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

    Thanks for your reply. All variables are of varchar data type. I feel some manipulation of ORs/ANDs is required. I have tried it but it gives weired results.

Regards
Monica






Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Query Problem mike.chary SQL Server 2005 1 September 26th, 2007 06:19 AM
SQL Query problem skarthikk SQL Server 2000 1 August 7th, 2006 02:20 AM
SQL query problem - Need Help Settt Biztalk 0 September 12th, 2005 09:32 AM
sql query problem Baby_programmer ASP.NET 1.0 and 1.1 Basics 1 October 14th, 2004 07:13 AM
Sql Query Problem mateenmohd SQL Language 0 January 13th, 2004 05:31 AM





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