ASPForums.Net RSS Feed additions to the content that appears on ASPForums.Net(c) 2019 All rights reserved.Insert record to Database Table based on condition using Stored Procedure in SQL Server<p>Hi <a class="username" rel="Waghmare"> Waghmare</a>,</p> <p>Refer below sample query.</p> <p><span style="text-decoration: underline;"><strong>SQL</strong></span></p> <pre class="brush: sql">CREATE TABLE #Sale_Details(Id INT,lastauditdate DATETIME) INSERT INTO #Sale_Details VALUES(1,GETDATE()) DECLARE @Date DATETIME SET @Date = GETDATE()-5 CREATE TABLE #TemTable(Id INT, lastauditdate DATETIME) IF(GETDATE()- 5 &lt; (SELECT TOP 1 lastauditdate FROM #Sale_Details ORDER BY Id DESC)) BEGIN INSERT INTO #TemTable(Id, lastauditdate) SELECT TOP 1 Id,lastauditdate FROM #Sale_Details ORDER BY Id DESC END SELECT * FROM #TemTable DROP TABLE #TemTable DROP TABLE #Sale_Details</pre> <p>&nbsp;</p>, 21 Jun 2019 08:18:51 GMT