Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions sql-generation/Generate SQL Insert Script/manual method.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
INSERT INTO students (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa)
VALUES (10, 'Alice Johnson', '5832043130', '2000-01-15', '2018-09-01', '2022-06-15', 3.75);

INSERT INTO students (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa)
VALUES (11, 'Bob Smith', '4448883118', '1999-05-20', '2017-09-01', '2021-06-15', 2.82);

INSERT INTO students (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa)
VALUES (12, 'Charlie Brown', '1023871400', '2001-03-12', '2019-09-01', '2023-06-15', 3.82);

INSERT INTO students (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa)
VALUES (13, 'Diana Prince', '1259075078', '2002-07-25', '2020-09-01', '2024-06-15', 3.47);

INSERT INTO students (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa)
VALUES (14, 'Ethan Hunt', '5120248524', '1998-12-11', '2016-09-01', '2020-06-15', 2.5);
2 changes: 2 additions & 0 deletions sql-generation/Generate SQL Insert Script/new data insert.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO Student (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa)
VALUES (7, ‘George Bailey’, 3125372499, ‘1997-08-14’, ‘2017-09-01’, ‘2021-06-15’, 3.41);
33 changes: 33 additions & 0 deletions sql-generation/Generate SQL Insert Script/using VBA.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Sub GenerateSQL()
Dim ws As Worksheet
Dim rowCount As Long
Dim sql As String
Dim outputFile As String
Dim i As Long
Dim id As Variant, name As String, national_id As String, birth_date As String, enrollment_date As String, graduation_date As String, gpa As Variant

Set ws = ThisWorkbook.Sheets(1)
rowCount = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
outputFile = "C:\Users\USER\Downloads\InsertScripts.sql"
Open outputFile For Output As #1

For i = 2 To rowCount
id = ws.Cells(i, 1).Value
name = ws.Cells(i, 2).Value
national_id = ws.Cells(i, 3).Value
birth_date = ws.Cells(i, 4).Value
enrollment_date = ws.Cells(i, 5).Value
graduation_date = ws.Cells(i, 6).Value
gpa = ws.Cells(i, 7).Value

If IsEmpty(id) Or IsEmpty(name) Then GoTo SkipRow
name = Replace(name, "'", "''")

sql = "INSERT INTO Student (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa) VALUES (" & _ id & ", '" & name & "', '" & national_id & "', '" & birth_date & "', '" & enrollment_date & "', '" & graduation_date & "', " & gpa & ");"
Print #1, sql

SkipRow:
Next i
Close #1
MsgBox "SQL scripts generated successfully!"
End Sub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
="INSERT INTO students (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa) VALUES (" & A2 & ", '" & B2 & "', '" & C2 & "', '" & D2 & "', '" & E2 & "', '" & F2 & "', " & G2 & ");"