Click here to Skip to main content
15,906,626 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have used OR command in sql server with select query but it is not working and shows syntax error.

What I have tried:

I had used this query to get data from table.

go
create procedure getpindata(@login varchar(50))
as
begin
(Select Balance_point, ExpiryDate from tblUserPlans where UserID = (Select [AutoId] from [UserDetail] where [UserName]=@login)) or (Select Balance_point, ExpiryDate from tblUserPlans where UserID = (Select [AutoId] from [Emp_Detail] where [LoginID]=@login));
end
Posted
Updated 18-Nov-20 22:55pm

I have no idea what you are trying to do with that query, but it's never going to work when you try to return multiple values and use them in a conditional statement - you can't say
SQL
(SELECT a, b FROM c) OR (SELECT a, b FROM c)
because it is meaningless.

Sit down and think about your data and what exactly you want to return and under what conditions. Then start thinking about what that means in terms of your DB and SQL.
If you can't work it out, then show us sample DB data, inputs to your SP and the outputs you expect, and explain why you should get those outputs. But at the moment your query is so badly formed that we can't work out what the heck you expect it to do! :D
 
Share this answer
 
Comments
Member 14743579 19-Nov-20 3:41am    
I got the solution, I have used if and else condition in my SQL query.
OriginalGriff 19-Nov-20 3:53am    
Excellent!
Try:
SQL
SELECT
    Balance_point, 
    ExpiryDate 
FROM
    tblUserPlans 
WHERE
    UserID = (SELECT [AutoId] FROM [UserDetail] WHERE [UserName] = @login)
Or
    UserID = (SELECT [AutoId] FROM [Emp_Detail] WHERE [LoginID] = @login)
;
 
Share this answer
 
Comments
Member 14743579 19-Nov-20 6:32am    
your query is running very well but I got the solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900