SQL Server Performance

Is it possible to insert a unique id with sum()

Discussion in 'Getting Started' started by postonoh, Apr 13, 2010.

  1. postonoh New Member

    Is it possible to insert a unique id with sum()
    I have a 2 sproc
    first sproc go something like this.
    Code:
    declare @p_Project_ID int, @Indentity1 int
    insert into Projects(Project_ID, ProjectName, ProjectNumber)
    [EMAIL]--@@Identity(Project_id);store[/EMAIL] it in local
    values(52, 'MEDical start1', '5465464546541')
    set @p_Project_ID = @@IDENTITY
    insert into PersonnelSummary (Date, Cleveland_Resident, DailyWork, Employee_Name, Gender, Minority, Position, Present, SubContractor, Project_ID, TradeContractor)
    values (04/02/2010, 1, 'woking', 'testing', 'male', 'yes', 'woking', 1, 'shelyb', @@IDENTITY, 'shelby')
    insert into Narrative (Date, ContructionManager, Location, MonitorSummary, MIM, MIF, MAF, MAM, Project_ID)
    Values (04/02/2010, 'tomas', 'cmc', 'testing1', 4,5,4,5, @p_Project_ID)
    
    second
    Code:
    insert into dbo.Manpower(Minority_Employees, Female_Employees, Total_Employees, Cleveland_Residents)
    Select SUM(Narrative.MIM),Sum(Narrative.MIF), SUM(Narrative.MAF + Narrative.MAM + Narrative.MIF + Narrative.MIM), SUM(PersonnelSummary.Cleveland_Resident)
    from Narrative, PersonnelSummary
    
    which displays in show table page. The problem I have a Project_ID int not null column in all the tables.
    The first one insert the Project_ID in all the tables it works perfectly except when it the same id i get an error.
    I need for it to place the Project_ID from the Narrative.Project_ID into the Manpower.Manpower_ID
    Please if you can not give me an example don't respond to the plea for help.
    I work off example.
    which displays in show table page. The problem I have a Project_ID int not null column in all the tables.
    The first one insert the Project_ID in all the tables it works perfectly except when it the same id i get an error.
  2. FrankKalis Moderator

    What error are you getting? Can you please post the error message? Sounds like you're trying to insert into a column that acts as the PRIMARY KEY or has a unique constraint defined on it.

Share This Page