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.
| Author |
Topic |
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2010-06-30 : 10:50:15
|
| I have an sp which inserts a record. It has about 60 parameters. I want my user to be able to click a button on my web oage which will insert null values for all the parameters (except where a default value is specified in the sql table) and create a record in the table with an id (identity autonumber). The user can then go back to this record and update fields etc using an update query to update the record in the table. Can i do this without having to code every null value as a parameter in my asp.net Also, how do i return the id to my webpage ? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-06-30 : 10:54:18
|
Your best choice is the default all input parameters to the stored procedure as NULL.To return the IDENTITY value you have a number of options1) Make use of OUTPUT parameter (preferrably the first if you default all other parameters as null)2) Make the SP return a resultset if a new record is inserted3) Set the return value (ie the error code) for the stored procedure to the new identity (not recommended) N 56°04'39.26"E 12°55'05.63" |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2010-06-30 : 11:02:30
|
Post the DDL, but Let's say the "Key" is the only NOT NULL Value......and you want a row per userCREATE PROCEDURE [dbo].[usp_Create_Template] @APPUSER char(30), @scope_identity int OUTPUTAS IF NOT EXISTS (SELECT* FROM <table> WHERE UserId = @APPUSER) BEGIN INSERT INTO <table> (appuser) SELECT @APPUSER SET @scope_identity = @@SCOPE_IDENTITY() END ELSE SELECT 'UserID: ' + @APPUSER + ' Already Exists'RETURN Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2010-06-30 : 11:20:45
|
| I don't want a row per user, just one blank record with an id - this errors though...CREATE PROCEDURE [dbo].[spCreateNewReport] @NextReportNo int OUTPUTAS IF NOT EXISTS (SELECT* FROM tblReports) BEGIN INSERT INTO tblReports @NextReportNo = @@IDENTITY RETURN @NextReportNoGO |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2010-06-30 : 12:17:30
|
Try This...Disclaimer: I am totally against this, unless you are actually try to record somethingCREATE TABLE myTable99( Col1 int IDENTITY(1,1), NewRecInd char(1), col3 int DEFAULT(0), col4 datetime DEFAULT(GetDate()))GOCREATE PROCEDURE [dbo].[usp_Create_Template] @scope_identity int OUTPUTAS INSERT INTO myTable99(NewRecInd) SELECT 'Y' SET @scope_identity = SCOPE_IDENTITY()RETURNGODECLARE @scope_identity intEXEC usp_Create_Template @scope_identity OUTPUTSELECT @scope_identity AS NEWLY_INSERTED_KEYSELECT * FROM myTable99 WHERE Col1 = @scope_identity-- Do it againEXEC usp_Create_Template @scope_identity OUTPUTSELECT @scope_identity AS NEWLY_INSERTED_KEYSELECT * FROM myTable99 WHERE Col1 = @scope_identitySELECT * FROM myTable99GODROP PROC [usp_Create_Template]DROP TABLE myTable99GO Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2010-07-01 : 03:40:09
|
| Why create a table ? I already have a table. I can't believe adding one record to a table is so difficult. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-07-01 : 03:55:41
|
Pinto, I don't think Brett has direct access to your server, so he has to mimic an environment that might look like yours.Run the complete sample code above, and you might be able to understand what the code does. N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|
|
|
|