|
-
Nov 10th, 2008, 05:35 AM
#1
Thread Starter
Junior Member
Sql2005 Stored Procedure
Hi
I want to create a stored procedure in SQL Server 2005 that takes 2 parameters:ArticleId int,and PersonNames nvarchar(255).
PersonNames are something like "John,Paula,Robert".
What I want is ,for each person in PersonNames ,to insert it into a table PersonsMentioned
so if ArticleId=987 and PersonNames ="John,Paula,Robert" so
PersonsMentioned(which has 3 fields ID,ArticleID,PersonMentioned) will have the following data
1 987 John
2 987 Paula
3 987 Robert
Any help
thanks
-
Nov 11th, 2008, 05:41 PM
#2
Re: Sql2005 Stored Procedure
Rather than nvarchar(255), use xml:
Code:
--for example only, these would be your input parms
declare @articleId int; set @articleId = 987
declare @personNames xml; set @personNames =
'<Persons>
<Name>John</Name>
<Name>Paula</Name>
<Name>Robert</Name>
</Persons>'
select @articleid, NAME.value('.','varchar(60)')
from @personNames.nodes('/Persons/Name') as Data(NAME)
That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma
Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|