473,395 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Stored Procedure

Hi,

I am modifying a stored proc to add a value to a table which results from a Select MAX from another Table.

#1.. Insert a Blank Dummy record to be updated at a later time

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO dbo.images
  2. (title, 
  3. largeimage, 
  4. thumbimage, 
  5. origimage, 
  6. album, 
  7. notes)
  8. VALUES (NULL, 
  9. NULL, 
  10. NULL, 
  11. NULL, 
  12. 9999, 
  13. NULL)
  14.  
  15. #2.. If the Insert worked pull the AutoIncrement Filed Id from the table 
  16.  
  17. IF( @@ERROR = 0 )
  18. BEGIN
  19. SELECT Max(id)as @ImageId from dbo.images 
  20. END 
  21.  
  22. #3.. Then later insert the value @ImageId into the desired Table
  23.  
  24. INSERT INTO dbo.aspnet_Membership
  25. ( ApplicationId,
  26. UserId,
  27. Password,
  28. PasswordSalt,
  29. Email,
  30. LoweredEmail,
  31. PasswordQuestion,
  32. PasswordAnswer,
  33. PasswordFormat,
  34. IsApproved,
  35. IsLockedOut,
  36. CreateDate,
  37. LastLoginDate,
  38. LastPasswordChangedDate,
  39. LastLockoutDate,
  40. FailedPasswordAttemptCount,
  41. FailedPasswordAttemptWindowStart,
  42. FailedPasswordAnswerAttemptCount,
  43. FailedPasswordAnswerAttemptWindowStart,
  44. ImageId )
  45. VALUES ( @ApplicationId,
  46. @UserId,
  47. @Password,
  48. @PasswordSalt,
  49. @Email,
  50. LOWER(@Email),
  51. @PasswordQuestion,
  52. @PasswordAnswer,
  53. @PasswordFormat,
  54. @IsApproved,
  55. @IsLockedOut,
  56. @CreateDate,
  57. @CreateDate,
  58. @CreateDate,
  59. @LastLockoutDate,
  60. @FailedPasswordAttemptCount,
  61. @FailedPasswordAttemptWindowStart,
  62. @FailedPasswordAnswerAttemptCount,
  63. @FailedPasswordAnswerAttemptWindowStart,
  64. @ImageId ) 
So my question is what should i define the @ImageId as within the Stored Procedure, also the Stored Procedure returns an error with the Select Statement as coded.

So how do I assign the Value of SELECT Max(id) from dbo.images to a Variable that can then be used in my Insert Command?
Mar 25 '06 #1
2 1390
dmj07
55
You should use:

SET @ImageID = SCOPE_IDENTITY()

This will return the auto increment file id after the first insert
Nov 26 '08 #2
Hi there,


The very first action you must take is declare the variable that will receive the id from the table

DECLARE @ImageID int

Hope this help you


Rpicilli
Nov 27 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dinesh prasad | last post by:
I'm trying to use a servlet to process a form, then send that data to an SQL server stored procedure. I'm using the WebLogic 8 App. server. I am able to retrieve database information, so I know my...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
3
by: Rhino | last post by:
I've spent the last couple of hours trying to figure out how to debug a Java stored procedure and am just going in circles. The last straw came when I got "Cannot open input stream for default"...
4
by: Rhino | last post by:
Is it possible for a Java Stored Procedure in DB2 V7.2 (Windows) to pass a Throwable back to the calling program as an OUT parameter? If yes, what datatype should I use when registering the...
8
by: Thomasb | last post by:
With a background in MS SQL Server programming I'm used to temporary tables. Have just started to work with DB2 ver 7 on z/OS and stumbled into the concept of GLOBAL TEMPORARY TABLE. I have...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
0
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how...
3
by: kd | last post by:
Hi All, How to debug a stored procedure? Thanks, kd
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
2
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.