Click here to Skip to main content
15,896,310 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi!

I have a view which I want to add a new column. This view I am creating, the data in the view is from two views (tableA and tableB). Let's just say tableC is my new view. I want the last column(column5) in my tableC in this condition:

For each data in TableC
if column2 of TableA <= column3 of TableB then column3 in tableC = 1
else column3 in tableC = 0
End For Each

Could this be possible? It is okay for me to create a new table. Just the last column should be in that condition stated above.

I am a newbie in SQL. Usually doing front-end, so I am new with all the terms in SQL.
I will be so blessed if some of you can help. Thanks.

Feel free to comment below for further instructions.
Posted

Just out of mind, not tested.

SQL
SELECT 
    CASE WHEN TableA.Column2 <= TableB.Colum3 THEN 1 ELSE 0 END AS Column3
FROM Table A INNER JOIN TableB ON ................
WHERE...................
 
Share this answer
 
v2
Comments
mitchiee1226 1-Jul-14 21:05pm    
CASE a.column2 <= b.column3 [THEN]<--Change this TRUE [1 ELSE]<--How come there is an Error here? 0 END AS billPaid
mitchiee1226 1-Jul-14 21:16pm    
Finally got your answer. Thanks! :D

CASE WHEN a.column2 >= b.column3 THEN 1 ELSE 0 END AS billPaid
[no name] 2-Jul-14 4:35am    
Answer updated.
Hi,

focusing on your condition, try below sql statement

SQL
CASE WHEN TABLEa.COL2 <= TABLEb.COL3 THEN TABLEc.COL3=1 ELSE  TABLEc.COL3=0 END


Hope this will help you.


Cheers
 
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