Personally, I'd like to know what you have done so far, but here is a solution anyway. I know you have been give some of the code used already, if not you can find here on ssc.
DECLARE @questionIdandchoiceid varchar(8000)='1-2,2-3,3-5' ;
DECLARE @Qout table(alid uniqueidentifier, QuestionID int);
DECLARE @question table
(
alid uniqueidentifier default newid(),
QuestionID int,
crdate datetime null,
IsActive bit null
);
DECLARE @Choice table
(
imid int identity(1,1),
alid uniqueidentifier,
ChoiceID int
);
with basedata as (
select
max(case ds2.ItemNumber when 1 then cast(ds2.Item as int) else null end) as QuestionID,
max(case ds2.ItemNumber when 2 then cast(ds2.Item as int) else null end) as ChoiceID
from
dbo.DelimitedSplit8K(@questionIdandchoiceid,',') ds1
cross apply dbo.DelimitedSplit8K(ds1.Item,'-') ds2
group by
ds1.ItemNumber,
ds1.Item
)
insert into
@Question(QuestionID)
output
inserted.alid, inserted.QuestionID
into
@Qout
select
bd.QuestionID
from
basedata bd;
with basedata as (
select
max(case ds2.ItemNumber when 1 then ds2.Item else null end) as QuestionID,
max(case ds2.ItemNumber when 2 then ds2.Item else null end) as ChoiceID
from
dbo.DelimitedSplit8K(@questionIdandchoiceid,',') ds1
cross apply dbo.DelimitedSplit8K(ds1.Item,'-') ds2
group by
ds1.ItemNumber,
ds1.Item
)
insert into
@Choice(alid, ChoiceID)
select
q.alid,
bd.ChoiceID
from
basedata bd
inner join @Qout q
on q.QuestionID = bd.QuestionID;
select * from @Question;
select *from @Choice;
Any questions, check Books Online. If still confused, post back.