I would like to perform an insert statement which the value come from the parameter. The value will consist of '|'
delimiter. I would like to insert the new row with the id come from SCOPE_IDENTITY
as well. I have tried using the SPLIT_STRING
but not sure on how to use with the external parameter and with the additional value.
Parameter Value from external source
@StudentName = John
@score =Science-90|Biology-100|Math-90
Insert table:
Main table
ID | StudentName |
---|---|
1 | John |
Score table
ID | StudentID | Score |
---|---|---|
1 | 1 | Science-90 |
2 | 1 | Biology-100 |
3 | 1 | Math-90 |
This is my stored procedure:
CREATE PROCEDURE [dhub_PushData]
@studentName varchar(50),
@score varchar(50)
AS
BEGIN
DECLARE @id bigint
INSERT INTO Student_Main (studentName)
VALUES (@studentName)
SELECT @id = SCOPE_IDENTITY()
-- Insert the score in every row which split by '|' with the @id from Student_Main table