Results 1 to 6 of 6

Thread: Where clause problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Location
    Pittsburgh, PA
    Posts
    149
    I am running a stored procedure on sql server 7. It runs fine so far except its ignoring one of the where clauses, a.mstatus='OP'. any idea why from the code below?

    Code:
    WHERE
    	b.clstatus='C' 
    	AND a.mstatus='OP'
    	AND b.corgaty='0575' OR a.msupaty='0575'

  2. #2
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274
    code:--------------------------------------------------------------------------------
    WHERE
    b.clstatus='C'
    AND a.mstatus='OP'
    AND b.corgaty='0575' OR a.msupaty='0575'
    --------------------------------------------------------------------------------

    Try this

    WHERE

    b.clstatus='C'
    AND a.mstatus='OP'
    AND (b.corgaty='0575' OR a.msupaty='0575')

    Also make sure that corgaty and msupaty are both character fields...if they aren't you need to remove the tick marks around the value 0575 in both cases.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Location
    Pittsburgh, PA
    Posts
    149
    Tried that earlier and it still ignored it plus it doesnt give me the right results. For some reason it just wants to completely ignor it. Here is the whole thing.
    Code:
    SELECT
    	clname1,
    	clnum,
    	(SELECT tklast FROM timekeep WHERE tkinit=corgaty),
    	(SELECT tkfirst FROM timekeep WHERE tkinit=corgaty),
    	mdesc1,
    	mmatter,
    	(SELECT tklast FROM timekeep WHERE tkinit=msupaty),
    	(SELECT tkfirst FROM timekeep WHERE tkinit=msupaty),
    	mstatus,
    	clstatus
    FROM
    	matter AS a
    	INNER JOIN client AS b
    		ON b.clnum=a.mclient
    WHERE
    	b.clstatus='C' 
    	AND a.mstatus='OP'
    	AND b.corgaty='0575' 
    	OR a.msupaty='0575'

  4. #4
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274
    Did you try putting parenthesis around the clause?


    WHERE
    ((b.clstatus='C'
    AND a.mstatus='OP')
    *must meet both criteria above
    AND
    (b.corgaty='0575'
    OR a.msupaty='0575'))
    *must meet one of the two criteria above


    ((b.clstatus='C' AND a.mstatus='OP') AND (b.corgaty='0575' OR a.msupaty='0575'))

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2000
    Location
    Pittsburgh, PA
    Posts
    149
    That worked, thanks

  6. #6
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274
    You're welcome

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width