MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 9th, 2004, 03:43 AM
chezza chezza is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 6 chezza User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cannot get OUTPUT from SP :o(



Hi,
I am new to T-SQL and would like some help with this stored procedure.

Basically, I am trying to check a table to see if a record already exists based on 2 parametres. If the record exists I would like to just output the ID from that record. If the record does not exist I would like to insert a new record outputting the ID.

The code seems to work except it does not output the ID when a new record has been created.

Can anyone see the problem?

Code:
CREATE PROCEDURE dbo.prInsertAssmtAttempt
(
	@AssmtInstID int,
	@AttemptNo int,
	@LastUpdateBy int,
	@AuditTypeID int,
	@AuditIP varchar(16),
	@AssmtAttemptID int OUTPUT
)
AS
DECLARE @Exist int

	SELECT *
	FROM tblAssmtAttempt
	WHERE tblAssmtAttempt.AssmtInstID = @AssmtInstID
	AND tblAssmtAttempt.AttemptNo = @AttemptNo	
	
	SET @Exist = @@ROWCOUNT

	IF @Exist = 0
	BEGIN
		SELECT @AssmtAttemptID = ISNULL(MAX(AssmtAttemptID),0) + 1 FROM tblAssmtAttempt
		INSERT INTO tblAssmtAttempt (AssmtAttemptID, AssmtInstID, AttemptNo, CreatedDate, LastUpdateBy, LastUpdated, AuditVersion, AuditCurrent, AuditTypeID, AuditIP)
		VALUES (@AssmtAttemptID, @AssmtInstID, @AttemptNo, GetDate(), @LastUpdateBy, GetDate(), 1, 1, @AuditTypeID, @AuditIP)
	END

	SELECT @AssmtAttemptID = AssmtAttemptID
	FROM tblAssmtAttempt
	WHERE tblAssmtAttempt.AssmtInstID = @AssmtInstID
	AND tblAssmtAttempt.AttemptNo = @AttemptNo
GO


Any help is much appreciated!
Thanks, Chezza

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Cannot get OUTPUT from SP :o(


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway