Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to use IDENTITY function
Message
 
 
To
14/03/2004 20:11:36
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00886170
Message ID:
00886177
Views:
14
SQL Server doesn't allow variables as parameters in IDENTITY() function. You can use dynamic SQL to get desired result.
...
DECLATE @Sql nvarchar(4000)
SET @Sql = 'select IDENTITY (tinyint, ' + CAST(@Num) AS nvrachar(3) + 
  ',1  ) AS id_num, ' +
  'MZ into aa from driverTemp ' +
  'where MZ IS NOT NULL group by MZ order by MZ'
EXECUTE (@Sql)
...
>Hello ,everyone!
>I use IDENTITY function is Error ,I don,t kown how to use IDENTITY()
>
>This is my code:
>use taxi
>IF EXISTS(SELECT TABLE_NAME 
FROM INFORMATION_SCHEMA.TABLES
>      WHERE TABLE_NAME = 'aa')
>   DROP TABLE aa
>GO
>
>declare @Num as tinyint
>select  @Num=max(CodeId)  from c_mz
>
>select IDENTITY (tinyint,@Num ,1  ) AS id_num, 
MZ into aa from driverTemp 
where   MZ IS NOT NULL group by MZ order by MZ
>
>go
>
>
>"Line 5 : '@Num' syntax error
>Why IDENTITY Arguments "send" cann't use variable
>What's wrong?
>
>Help me ,thanks!
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform