Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Dave http://pedotnet.blogspot.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

MSSQL 2005 - Add ID value to ID column when INSERTING

// @TableName is obviously the TABLE name u use
// @ColumnName is obviously the COLUMN name u use

   1  
   2  ---Get next ID number
   3  	DECLARE 
   4  		@ID int
   5  	
   6  	IF (SELECT count(*) FROM @TableName ) > 0
   7  		BEGIN
   8  			SELECT @ID  = max(ColumnName ) from @TableName
   9  			SET @ID = @ID + 1 
  10  		END
  11  	ELSE
  12  	BEGIN
  13  		SET @ID  = 1
  14  	END
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS