Solved

How would you create a stored procedure to insert records containing a field that has mulitple values using SQL Server 2005?

Posted on 2012-04-10
1
179 Views
Last Modified: 2012-04-16
I am creating a Stored Procedure to insert records into a table using SQL Server 2005.

I have a table titled tblA with the following 3 fields and the last field titled

ELEMENT_TYPE_VALUE_PAIRS can have mulitple values in it's field:

ID_TYPE     PRIN_NAME   ELEMENT_TYPE_VALUE_PAIRS

K                          smithj           {(User_Type, Master Access)}  
K                          smithj           {{(Holder,holder-1),(Action,All)}}  
K                          smithj           {{(Holder,holder-2),(Action,Update)}}                
K                          cliffr              {{(Holder,holder-1),(Action,Browse)}}  
K                          cliffr              {(User_Type,Security Officer Access)}  

How would you create a stored procedure to populate table tblA with the values listed above?
0
Comment
Question by:zimmer9
1 Comment
 
LVL 11

Accepted Solution

by:
f_o_o_k_y earned 500 total points
ID: 37830142
I would use this:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Fooky
-- Create date: 2012-04-10
-- Description:	simple insert
-- =============================================
CREATE PROCEDURE sp_simple_insert 
	-- Add the parameters for the stored procedure here
	@id_type int, 
	@name varchar(50),
	@value varchar(1000)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	INSERT INTO table( ID_TYPE  ,   PRIN_NAME ,  ELEMENT_TYPE_VALUE_PAIRS)
	VALUES(@id_type,@name,@value)
END
GO

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip Migration Tip #1 – Source Server Health can be found listed in my profile here: http:…
Have you considered what group policies are backwards and forwards compatible? Windows Active Directory servers and clients use group policy templates to deploy sets of policies within your domain. But, there is a catch to deploying policies. The…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now