Click here to Skip to main content
15,911,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have summary table which contains tHREE columns Accountno,datetime,Status.Data looks like

Accountno
DATETIME  
Status

1212 2018-03-12 16:13:21 No
1212 2018-02-12 16:13:21 Yes
1212 2018-01-12 16:13:21 Yes
1211 2018-03-12 16:13:21 Yes
1211 2018-02-12 16:13:21 No

I have master table containing Accountno.

Now i want to get top Datetime along with Status='Yes' for the accountno

What I have tried:

Yes but not getting actual data
Posted
Updated 7-May-18 20:48pm

Try:
SQL
SELECT TOP 1 AccountNo, [datetime] FROM MyTable
WHERE Status = 'Yes'
ORDER BY [datetime] DESC
 
Share this answer
 
v2
Comments
krishnaraosan 8-May-18 2:38am    
i need to join with master table for all accounts not only for one account
Try this:
SQL
SELECT S.*, M.*
FROM Summary AS S INNER JOIN Master AS M ON S.Accountno = M.Accountno
WHERE S.Status = 'Yes' AND [datetime] > DATEADD(DD, -1, GETDATE())
--returns last day data




More at: Visual Representation of SQL Joins[^]
DATEADD (Transact-SQL) | Microsoft Docs[^]
 
Share this answer
 
v2

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