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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 WHAT IS WRONG WITH QUERY

Author  Topic 

asifbhura
Posting Yak Master

165 Posts

Posted - 2010-03-30 : 05:06:40
SELECT * FROM Vacation_Process WHERE
(chairman_Isaction='Yes' AND Chairman_Approve='1')
OR (Isaction_0='Yes' AND IsLevel0_Approve='1')
OR (Isaction_1='Yes' AND IsLevel1_Approve='1')
OR (Isaction_2='Yes' AND IsLevel2_Approve='1')
OR (Isaction_3='Yes' AND IsLevel3_Approve='1')
and (isAction_HR='No' AND emp_id is not null)

this is my query but it doesnt return correct records

it shows also Is_Action_HR='Yes'

actually i want records where all bracket conditions must be true and

emp_id is not null and isAction_HR='No'

any other solution would be appriciated

Regards,
ASIF

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-30 : 05:08:51
SELECT * FROM Vacation_Process WHERE
(chairman_Isaction='Yes' AND Chairman_Approve='1')
and (isAction_HR='No' AND emp_id is not null)
(
OR (Isaction_0='Yes' AND IsLevel0_Approve='1')
OR (Isaction_1='Yes' AND IsLevel1_Approve='1')
OR (Isaction_2='Yes' AND IsLevel2_Approve='1')
OR (Isaction_3='Yes' AND IsLevel3_Approve='1')
)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Buzzard724
Yak Posting Veteran

66 Posts

Posted - 2010-03-30 : 05:10:12
(chairman_Isaction='Yes' AND Chairman_Approve='1'
AND isAction_HR='No' AND emp_id is not null)
AND
((Isaction_0='Yes' AND IsLevel0_Approve='1')
OR (Isaction_1='Yes' AND IsLevel1_Approve='1')
OR (Isaction_2='Yes' AND IsLevel2_Approve='1')
OR (Isaction_3='Yes' AND IsLevel3_Approve='1'))
Go to Top of Page

asifbhura
Posting Yak Master

165 Posts

Posted - 2010-03-30 : 05:15:18
not working both of them
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-30 : 05:17:16
Post some sample data with expected result

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

asifbhura
Posting Yak Master

165 Posts

Posted - 2010-03-30 : 05:26:40
I have one one records of all condition i run your query it gives error
like

Msg 156, Level 15, State 1, Line 32
Incorrect syntax near the keyword 'OR'.
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-03-30 : 05:43:43
A small correction in madhivanam's query.
I feel its typo error.

SELECT * FROM Vacation_Process WHERE
(chairman_Isaction='Yes' AND Chairman_Approve='1')
and (isAction_HR='No' AND emp_id is not null)
AND
(
(Isaction_0='Yes' AND IsLevel0_Approve='1')
OR (Isaction_1='Yes' AND IsLevel1_Approve='1')
OR (Isaction_2='Yes' AND IsLevel2_Approve='1')
OR (Isaction_3='Yes' AND IsLevel3_Approve='1')
)

Regards,
Bohra


I am here to learn from Masters and help new bees in learning.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-03-30 : 05:50:07
The WHERE clause is mising a predicate.

SELECT *
FROM
Vacation_Process
WHERE
(chairman_Isaction='Yes' AND Chairman_Approve='1')
and (isAction_HR='No' AND emp_id is not null)

<INSERT LOGIC HERE> (
OR (Isaction_0='Yes' AND IsLevel0_Approve='1')
OR (Isaction_1='Yes' AND IsLevel1_Approve='1')
OR (Isaction_2='Yes' AND IsLevel2_Approve='1')
OR (Isaction_3='Yes' AND IsLevel3_Approve='1')
)



Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -