Important alert: (current site time 7/15/2013 7:55:04 PM EDT)
 

VB icon

tgrPostData

Email
Submitted on: 3/23/2004 11:26:05 PM
By: Raalnan Five  
Level: Intermediate
User Rating: By 1 Users
Compatibility: SQL Server 2000, SQL Server 7.0, SQL Server 6.5 and earlier
Views: 7794
author picture
(About the author)
 
     Split an insertion and distribute it to seperate tables.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
--**************************************
-- for :tgrPostData
--**************************************
Mackin' harder than a two-headed pimp with a Ho-Slappin Machine.
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
--**************************************
-- Name: tgrPostData
-- Description:Split an insertion and distribute it to seperate tables.
-- By: Raalnan Five
--
-- Inputs:Distribution Table Fields.
--
-- Returns:Distribution Table Fields if necessary
--
-- Assumes:You should know the basics of triggers
--
-- Side Effects:A feeling of euphoria
--
--This code is copyrighted and has-- limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=820&lngWId=5--for details.--**************************************

--System Generated SQL has a tendancy to be a little heavier than it needs to be.
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblAnswer]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblAnswer]
GO
CREATE TABLE [dbo].[tblAnswer] (
	[ClassName] [nvarchar] (255) NULL ,
	[QuestionID] [int] NULL ,
	[AnswerID] [int] IDENTITY (1, 1) NOT NULL ,
	[Answer] [varchar] (8000) NULL 
) ON [PRIMARY]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblQuestion]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblQuestion]
GO
CREATE TABLE [dbo].[tblQuestion] (
	[ClassName] [nvarchar] (255) NULL ,
	[QuestionID] [int] IDENTITY (1, 1) NOT NULL ,
	[Question] [nvarchar] (255) NULL 
) ON [PRIMARY]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tgrPostData]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
drop trigger [dbo].[tgrPostData]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblQA]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblQA]
GO
CREATE TABLE [dbo].[tblQA] (
	[Question] [varchar] (8000) NULL ,
	[Answer] [varchar] (8000) NULL ,
	[QuestionID] [int] IDENTITY (1, 1) NOT NULL 
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
CREATE TRIGGER tgrPostData ON [dbo].[tblQA]
FOR INSERT
AS
Begin	--	Transactions keep code clean!
	Declare @QuestionID int, @Answer VarChar(8000), @Question VarChar(8000)	--	Let there be light! (Establish variables to hold values)
	Set @Answer = (Select Answer From Inserted)	--	ShoveIt (put the necessary values into variables)
	Set @Question = (Select Question From Inserted)	--	ShoveIt (put the necessary values into variables)
	
	Insert Into tblQuestion(Question) Values(@Question)	--	HeelFlip
	Set @QuestionID = (Select @@Identity From Inserted)	--	ReBate
	Insert into tblAnswer(Answer, QuestionID) Values(@Answer, @QuestionID)	--	KickFlip
End
--	Questions, EMail me at Raalnan5@Cox.net
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
3/13/2005 8:11:02 AMtrinadh

This is really a cool code, even included creating sample tables. I was searching for something like this, Thank you.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.