Skip to content

Commit 438526a

Browse files
authored
Add files via upload
1 parent 200312d commit 438526a

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
INSERT INTO Student (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa)
2+
VALUES (7, ‘George Bailey’, 3125372499, ‘1997-08-14’, ‘2017-09-01’, ‘2021-06-15’, 3.41);
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
="INSERT INTO students (id, name, national_id, birth_date, enrollment_date, graduation_date, gpa) VALUES (" & A2 & ", '" & B2 & "', '" & C2 & "', '" & D2 & "', '" & E2 & "', '" & F2 & "', " & G2 & ");"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Sub GenerateSQL()
2+
Dim ws As Worksheet
3+
Dim rowCount As Long
4+
Dim sql As String
5+
Dim outputFile As String
6+
Dim i As Long
7+
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
8+
9+
Set ws = ThisWorkbook.Sheets(1)
10+
rowCount = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
11+
outputFile = "C:\Users\USER\Downloads\InsertScripts.sql"
12+
Open outputFile For Output As #1
13+
14+
For i = 2 To rowCount
15+
id = ws.Cells(i, 1).Value
16+
name = ws.Cells(i, 2).Value
17+
national_id = ws.Cells(i, 3).Value
18+
birth_date = ws.Cells(i, 4).Value
19+
enrollment_date = ws.Cells(i, 5).Value
20+
graduation_date = ws.Cells(i, 6).Value
21+
gpa = ws.Cells(i, 7).Value
22+
23+
If IsEmpty(id) Or IsEmpty(name) Then GoTo SkipRow
24+
name = Replace(name, "'", "''")
25+
26+
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 & ");"
27+
Print #1, sql
28+
29+
SkipRow:
30+
Next i
31+
Close #1
32+
MsgBox "SQL scripts generated successfully!"
33+
End Sub

0 commit comments

Comments
 (0)