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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 GET NEW ID

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-05-07 : 11:21:20
Alireza writes "What is best way to calculate a New Id for a Field.
i dont want to using Identity=true.

also how can using Function Parameters as TableName.
For Expamle I wrote this Function

CREATE FUNCTION dbo.GETLastID (@TableName varchar(40) )
RETURNS bigint
AS
BEGIN
DECLARE @LASTID bigint
SET @LASTID=1
SET @LASTID=(select max(ID) from @TableName ) + 1
IF @LASTID IS NULL
SET @LASTID=1

RETURN @LASTID
END


but we get error for @tablename.

please help me.
thanks"

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2004-05-07 : 11:25:37
look into "dynamic sql"....
Go to Top of Page
   

- Advertisement -