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 |
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-09-03 : 11:22:59
|
| HelloI am very new to write SP,so need guidance in doing the following.I need to write a stored procedure,which will insert data into 3 tables.These are the 3 tableTable-TOCHeaderSchemaColumns-TOCHeaderSchemaID -TocHeaderScemaNameText -CreatedByLIDTable-TOCHSElementColumns-TOCHSElementID -TOCHSLevel -TOCHSPrefixText -TOCHSCounterStyleID -TOCHeaderSchemaIDTable-TOCHSCounterStyleColumns-TOCHSCounterStyleID -TOCHSCounterNumber----this is autogenerated -TOCHSCounterLabelTextBasically these tables are changing the numbering of elements.like for example.this is the numbering of a document named Transportation TP 1.1.1so this will be changed to 1.A.1 or 1.a.1 depending upon the choice.so the table TOCHSCounterStyle is likeTOCHSCounterStyleID ---1TOCHSCounterNumber----1,2,3,4,5(autogenerated)TOCHSCounterLabelText----A,B,C,D,ETOCHSCounterStyleID ---2TOCHSCounterNumber----1,2,3,4,5(autogenerated)TOCHSCounterLabelText----a,b,c,dTOCHSCounterStyleID ---3TOCHSCounterNumber----1,2,3,4,5(autogenerated)TOCHSCounterLabelText----i,ii,iii,iv,v...Thank You |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2008-09-03 : 13:07:41
|
Heres an example of creating a test stored procedure that does a simple insert into a test table. Forgive me if this is too elementary for you, im just trying to start at the beginning of using stored procedures.-- if table exists already we must delete first before trying to create itif object_id('dbo.Test') is not nullbegin drop table dbo.Testend-- now create the new table with an identity (autogenerated) Primary Key create table dbo.Test (TestId int identity(1,1) primary key, TestName varchar(25)) -- insert data into new table, do not insert into the identity because that is managed by the table identityinsert into dbo.Test (TestName) values ('Test direct insert') -- return the resultsselect TestId, TestName from dbo.Test-- drop if exists, then create a new stored proc to take in the TestName as a parameter and do the insertif object_id('dbo.usp_InsertTest') is not nullbegin drop procedure dbo.usp_InsertTestend;gocreate procedure dbo.usp_InsertTest (@TestName varchar(25))asset nocount oninsert into dbo.Test (TestName) values (@TestName)go-- exec the stored proceduredeclare @TestName varchar(25)set @TestName = 'Test from proc'exec dbo.usp_InsertTest @TestName-- return the resultsselect TestId, TestName from dbo.TestNathan Skerl |
 |
|
|
|
|
|
|
|