October 6, 2022 at 2:02 pm
I am trying to insert same set of records with student id 1234 (All 4 records with student id 1234 needs to be inserted into same table but instead of
student id 1234. i want the id to be selected 9876)
Below is the sample data Student ID 1234 below points to specific case from casetype table where type = 'HOLL' and Subtype = 'SUXX'
Student ID 9876 below points to specific case from casetype table where type = 'HOLL' and Subtype = 'GEN'
StudentID StudentName StudentKey StudentAccKey StartDate EndDate
1234 john 12455666 875755656 2022-10-06 NULL
1234 jim 12455666 875755656 2022-10-06 NULL
1234 Sam 12455666 875755656 2022-10-06 NULL
1234 Jack 12455666 875755656 2022-10-06 NULL
9876 Rap 12455666 567776665 2022-10-06 NULL
9876 Swer 12455666 567776665 2022-10-06 NULL
I am selecting columns from student table. where type = 'HOLL' and Subtype = 'SUXX' , in that case only those 4 records with student id 1234 will be inserted.
but how i can change or update student id to different 9876 in the select caluse. I tried to use case statement in select but it didnt worked
like case when ct.type = 'HOLL' and ct.Subtype = 'GEN' then ct.studentid end as studentid
insert into Student (studentid,
StudentName,
StudentKey,
StudentAccKey,
StartDate,
EndDate)
SELECT studentid,
StudentName,
StudentKey,
StudentAccKey,
StartDate,
EndDate
FROM Student std
join casetype ct on std.studentid = ct.studentid
where ct.type = 'HOLL' and ct.Subtype = 'SUXX' and std.StudentKey = 12455666
October 6, 2022 at 3:20 pm
This is as clear as mud. You've been around long enough to know that you should post sample data and expected results using (temp) table creates and inserts.
Also, what is the logic for substituting 9876 for 1234?
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
October 6, 2022 at 5:53 pm
If this is a one off, then instead of the studentid in the SELECT, then put the scalar value instead.
As Drew noted, however, make your question easier for people to answer with code (formatted).
October 6, 2022 at 9:53 pm
You have 1 common StudentAccKey with 1 common StudentKey and 1 common StartDate.
And yet there are two StudentID's and six different StudentName's.
The code that you're using to get the data has a massive problem and you need to fix that before doing anything else.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 11, 2022 at 5:35 pm
ID Grpkey StudentKey StudentLockKey StudentPeriodKey BeginDate EndDate Type SubType
5799 1234 1224567 8876535 1298777 2020-1-20 NULL HOLL SUX
5799 4355 1224567 8876535 1298785 2020-1-20 NULL HOLL SUX
5799 2677 1224567 8876535 1298789 2020-1-20 NULL HOLL SUX
5799 7645 1224567 8876535 1298790 2020-1-20 NULL HOLL SUX
5799 2456 1224567 8876535 1298791 2020-1-20 NULL HOLL SUX
9876 6788 1224567 8876535 1298793 2020-1-20 NULL HOLL GEN
9876 8664 1224567 8876535 1298796 2020-1-20 NULL HOLL GEN
9876 5777 1224567 8876535 1298791 2020-1-20 NULL HOLL GEN
Here is sample Data.
For mockup Data, We are trying to insert same set of records with ID 5799 (total 5 records) into same table , but i dont want all 5 records with same ID 5799.
it shoudl be different caseid 9876. for those first 5 records. When ever student detail records gets created on UI it creates with an ID and associated to Type and SUb type.
October 12, 2022 at 12:31 am
Didn't Steve answer your question? Seemed pretty clear to me. you just overwrite the ID = 1234 with another value.
insert into Student (studentid,
StudentName,
StudentKey,
StudentAccKey,
StartDate,
EndDate)
SELECT 9786,
StudentName,
StudentKey,
StudentAccKey,
StartDate,
EndDate
FROM Student std
join casetype ct on std.studentid = ct.studentid
where ct.type = 'HOLL' and ct.Subtype = 'SUXX' and std.StudentKey = 12455666
October 12, 2022 at 12:29 pm
Yes he answered, i got it. But the question is we cannot hardcode 9786 in select. because there are tons of records with different student keys. i Just took sample student key. We have to insert the records for each student key based on type and sub type. but in select we have to use id as with type HOLL and Subtype GEN. for each student key.
October 12, 2022 at 2:28 pm
You haven't explained how you use the other keys. What you need to do is help develop an algorithm. Explain for 1234 how you derive this? Or for 9786, how do you use other values to get this.
October 12, 2022 at 3:14 pm
We have to insert the records for each student key based on type and sub type. but in select we have to use id as with type HOLL and Subtype GEN. for each student key.
What do you mean by "based on"? Be specific, because it is not clear.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply