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.
| Author |
Topic |
|
best_boy26
Starting Member
42 Posts |
Posted - 2011-03-07 : 12:49:11
|
| I have Two table's called O3 and o5 and contains s.no and O3 & O5 in the Table (i.e..in O3 & O5). and s.no will be matches in both the tables. Now i want to run a query to get if the O3_Value (O3) value is more than O5_Value (O5) then i should get True as output in one column. And also in another coloumn the O5 Value should be displayed.I am able to match the SQL Query however the Greater than O3 logic iam missing...:( need you help here...SELECT dbo.O3.[s.no] AS [O3_Sn.NO], dbo.O5.[s.no] AS [O5_Sn.NO], dbo.O3.O3, dbo.O5.O5FROM dbo.O3 INNER JOIN dbo.O5 ON dbo.O3.[s.no] = dbo.O5.[s.no]----o3 Table has below datas.no o31 102 123 134 155 16----05 Table has below Datas.no o51 112 113 94 125 7---------My Actual query should display as below output s.no Flag O5 Value1 TRUE 112 TRUE 113 FALSE 94 FALSE 125 FALSE 7My SQL query putput should be like as below |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2011-03-07 : 13:12:43
|
Should just be able to add a CASE statement to do that logic:SELECT O3.[s.no] ,CASE WHEN O3.o3 > O5.o5 THEN 'TRUE' ELSE 'FASLE' END AS Flag ,O5.o5 AS ValueFROM O3INNER JOIN O5 ON O3.[s.no] = O5.[s.no] |
 |
|
|
|
|
|