Translate to Tamil

Earn Money


Best Offers

Amazon Best Offers

Offers

Best Online Offers

Amazon Offers

Earn Money Short URL

Thursday, 10 November 2011

Sql Store Procedure Dynamic Query Get Max Record




Dynamic Query Get Max Record Multiple table




CREATE PROC Get_Max_ID_SP (@tblName VARCHAR(50),@ClmnName VARCHAR(50))
AS
BEGIN


DECLARE @Qry NVARCHAR(MAX)
DECLARE @Ret NVARCHAR(MAX)
DECLARE @Param NVARCHAR(MAX)

SELECT @Param='@Val NVARCHAR(MAX) OUTPUT'
SELECT @Qry='SELECT @Val =ISNULL(MAX('+@ClmnName+'),0)+1 FROM ' + @tblName

    EXEC  SP_EXECUTESQL  @Qry,@Param,@Val=@Ret OUTPUT  
    
    SELECT @Ret as  MaxCust

END

Output :

exec  Get_Max_ID_SP 'DistMast','Distcode'

Result :

MaxCust
5


Reference Link:



  


   

No comments:
Write comments

Contact form

Name

Email *

Message *

Infolinks

© 2014