|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
IDENTITY based on a second valueUsing SqlServer 2005. At a INSERT statement I want CustomId to increase with 1 depending on what the AppId are. CustomId must be unique per AppId. Any ideas on how to solve this? CREATE TABLE [Invoice] ( [Id] [int] IDENTITY (1, 1) NOT FOR REPLICATION NOT NULL , [AppId] [int] NOT NULL , [CustomId] [int] NOT NULL , CONSTRAINT [PK_Invoice] PRIMARY KEY CLUSTERED ( [Id] ) ON [PRIMARY] ) ON [PRIMARY] GO --Fill with temp data INSERT INTO [dbo].[Invoice]([AppId], [CustomId]) VALUES(1,1) INSERT INTO [dbo].[Invoice]([AppId], [CustomId]) VALUES(1,2) INSERT INTO [dbo].[Invoice]([AppId], [CustomId]) VALUES(2,1) INSERT INTO [dbo].[Invoice]([AppId], [CustomId]) VALUES(1,3) INSERT INTO [dbo].[Invoice]([AppId], [CustomId]) VALUES(1,4) INSERT INTO [dbo].[Invoice]([AppId], [CustomId]) VALUES(1,5) INSERT INTO [dbo].[Invoice]([AppId], [CustomId]) VALUES(2,2) INSERT INTO [dbo].[Invoice]([AppId], [CustomId]) VALUES(1,6) --View temp data SELECT * FROM dbo.Invoice |
|||||||||||||||||||||||