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
180 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On a regular basis I get questions about slow RDP performance, RDP connection problems, strange errors and even BSOD, remote computers freezing or restarting after initiation of a remote session. In a lot of this cases the quick solutions made b…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 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

14 Experts available now in Live!

Get 1:1 Help Now