Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
ect O.OrderID,D.OrderDetailID,ProductName,
--case when R.OrderDetailID   = 65 then '0'
--else '1'
--end

IF (D.OrderDetailID != R.OrderDetailID) Then '1'
Else '0'
end
--Returned='0'
From dbo.vOrderDetails D Join tblOrders O On O.OrderID = D.OrderID
Join tblCustomerLogins L On O.CustomerID = L.CustomerID
join tblOrderReturns R on R.OrderDetailID = D.OrderDetailID
Where O.OrderID = 65 And L.SessionID ='8004837C7D62qdSV8'


If condition is not correct format
Posted
Updated 23-Jan-15 3:10am
v2
Comments
Tomas Takac 23-Jan-15 9:18am    
Why is the "case" commented out? That's actually the correct solution. You cannot use "if-else" in select list like that. BTW there is no "then" in T-SQL.
jaket-cp 23-Jan-15 9:56am    
then for when but not of if..else
right :)

You can use the CASE as you have tried. Sommthing like:
SQL
select O.OrderID,D.OrderDetailID,ProductName,
case 
   when D.OrderDetailID != R.OrderDetailID then '1'
   else '0'
end as ColName
From dbo.vOrderDetails D 
     Join tblOrders O         On O.OrderID = D.OrderID
     Join tblCustomerLogins L On O.CustomerID = L.CustomerID
     join tblOrderReturns R   On R.OrderDetailID = D.OrderDetailID
Where O.OrderID = 65 
And L.SessionID ='8004837C7D62qdSV8'

For details see CASE (Transact-SQL)[^]
 
Share this answer
 
v4
Comments
jaket-cp 23-Jan-15 9:55am    
the then is missing for the when
:)
Wendelius 23-Jan-15 10:04am    
Good catch thanks :) Fixed now.
jaket-cp 23-Jan-15 10:05am    
no prob 5ed :)
It can be done using Case statement.
[Check here]
 
Share this answer
 
Use Case statement instead. Have a look at below link for more information.

http://www.techonthenet.com/sql_server/functions/case.php
 
Share this answer
 

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