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 2005 Forums
 Transact-SQL (2005)
 SP error

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2007-03-28 : 06:45:35
I am getting the following error if there are no records in the table. The 'project_priority' field in an int

Cannot insert the value NULL into column 'project_priority', table 'nsvrc.dbo.Projects'; column does not allow nulls. INSERT fails.

The statement has been terminated.



ALTER PROCEDURE dbo.InsertProject

(
@txtTopic AS VARCHAR(100),
@userid AS int,
@maxID as int OUTPUT
)
AS
SET NOCOUNT ON
INSERT INTO Projects (project_priority, project_Desc, userID, lastModified)
SELECT MAX(project_priority)+1, @txtTopic,@userid, GETDATE() FROM Projects
SET @maxID = Scope_Identity()
SET NOCOUNT OFF
RETURN

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-28 : 06:46:49
quote:
Originally posted by helixpoint

I am getting the following error if there are no records in the table. The 'project_priority' field in an int

Cannot insert the value NULL into column 'project_priority', table 'nsvrc.dbo.Projects'; column does not allow nulls. INSERT fails.

The statement has been terminated.



ALTER PROCEDURE dbo.InsertProject

(
@txtTopic AS VARCHAR(100),
@userid AS int,
@maxID as int OUTPUT
)
AS
SET NOCOUNT ON
INSERT INTO Projects (project_priority, project_Desc, userID, lastModified)
SELECT IsNull(MAX(project_priority),0)+1, @txtTopic,@userid, GETDATE() FROM Projects
SET @maxID = Scope_Identity()
SET NOCOUNT OFF
RETURN



Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-28 : 06:49:19
[code]ALTER PROCEDURE dbo.InsertProject
(
@TxtTopic VARCHAR(100),
@UserID INT,
@MaxID INT OUTPUT
)
AS

SET NOCOUNT ON

SELECT @MaxID = MAX(Project_Priority)
FROM Projects

IF @MaxID IS NULL
SET @MaxID = 1

INSERT Projects
(
Project_Priority,
Project_Desc,
UserID,
LastModified
)
VALUES (
@MaxID,
@TxtTopic,
@UserID,
CURRENT_TIMESTAMP
)

SET NOCOUNT OFF

SET @MaxID = SCOPE_IDENTITY()[/code]
Peter Larsson
Helsingborg, Sweden
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-03-28 : 07:20:49
its trying to tell you that Project_Priority is supposed to be an IDENTITY field

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page
   

- Advertisement -