Declare @Frogs table
(
id int primary key identity(1,1) not null
, legs int
, color varchar(36)
, spots int
)
Insert into @Frogs (legs, color, spots) values (5, 'blue', 3)
Insert into @Frogs (legs, color, spots) values (4, 'red', 7)
Insert into @Frogs (legs, color, spots) values (8, 'purple', 22)
declare @Ponds table
(
pid int primary key identity (1,1) not null
, id int
, location varchar (30)
, color varchar (20)
, weeds varchar (30)
)
insert into @Ponds (id, location, color, weeds) values (1, 'Fargo', 'blue', 'Full')
insert into @Ponds (id, location, color, weeds) values (2, 'Grand Forks', 'green', 'Half full')
insert into @Ponds (id, location, color, weeds) values (3, 'Hillsboro', 'blue-green', 'Quarter full')
select f.legs
,f.color
,p.location
from @Ponds p
inner join @Frogs f
on f.id=p.id
order by f.id
Monday, January 31, 2011
Create inner join on 2 tables in SQL
Blog post: Research and test the creation of 2 table variables, insert 3 records into each, both having a column in common, and select all records from both tables by joining them together. You can use a join or an inner join for this.
Word Problem 6 - Quiz scores
a.) Given the table of quiz marks out of 25 in each subject calculate How many marks did Brian totally obtain in Mathematics and Science?
Write a program in Visual Basic to calculate the marks Brian obtained in Mathematics and Science.
b.) How many more marks does Andrew need for a perfect score in Mathematics?
c.) What is Andrew's percentage for all of the quizzes together?
Write a program in Visual Basic to calculate the marks Brian obtained in Mathematics and Science.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare variables
Dim M, S, marks As Integer
'Set values
M = 7 'Marks in Mathmetics
S = 22 'Marks in Science
marks = M + S
'Display results
MessageBox.Show("Brian has " & marks & " marks in Mathematics and Science.")
End Sub
End Class
b.) How many more marks does Andrew need for a perfect score in Mathematics?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare variables
Dim M, S, marks As Integer
'Set values
M = 18 'Brian's actual marks
S = 25 'total possible
marks = S - M
'Display results
MessageBox.Show("Brian needs " & marks & " marks for a perfect score in Mathematics.")
End Sub
End Class
c.) What is Andrew's percentage for all of the quizzes together?
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare variables
Dim M, S, En, G As Integer
Dim marks As Decimal
'Set values
M = 18 'marks in Mathematics
S = 7 'marks in Science
En = 12 'marks in English
G = 15 'marks in Geography
marks = (S + M + En + G) / 100
'Display results
MessageBox.Show("Brian has " & FormatPercent(marks) & " marks for all the quizzes together.")
End Sub
End Class
Word Problem 5 - Inglebert's Apples and Oranges with variable
Inglebert has 15 apples and 3 times as many oranges. How may pieces of fruit does she have?
Create a program in Visual Basic to calculate the number of pieces of fruit that Inglebert has. Enter the initial value for apples in a text box.
Create a program in Visual Basic to calculate the number of pieces of fruit that Inglebert has. Enter the initial value for apples in a text box.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare variables
Dim A, O, pieces As Integer
'Set values
A = txtInitial.Text
O = A * 3
pieces = A + O
'Display results
MessageBox.Show("Inglebert has " & pieces & " pieces of fruit.")
End Sub
End Class
Word Problem 5 - Inglebert's Apples and Oranges
Inglebert has 15 apples and 3 times as many oranges. How many pieces of fruit does she have?
Create a program in Visual Basic to calculate the number of pieces of fruit Inglebert has with the given numbers.
Create a program in Visual Basic to calculate the number of pieces of fruit Inglebert has with the given numbers.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare variables
Dim A, O, pieces As Integer
'Set values
A = 15
O = A * 3
pieces = A + O
'Display results
MessageBox.Show("Inglebert has " & pieces & " pieces of fruit.")
End Sub
End Class
Word Problem 4 - Horses in the field part 2
There are 33 horses in a field. 15 horses go into the barn. Then 7 of them come back out. How many horses are standing in the field?
Write a program in Visual Basic to find out how many horses are standing in the field.
Gather the initial value in a text box.
Write a program in Visual Basic to find out how many horses are standing in the field.
Gather the initial value in a text box.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare variables
Dim I, O, B, horses As Integer
'Set values
O = 15
I = txtInitial.Text
B = 7
horses = I - O + B
'Display results
MessageBox.Show("There are " & horses & " horses in the field.")
End Sub
End Class
Word Problem 4 - Horses in the field
There are 33 horses in a field. 15 horses go into the barn. Then 7 of them come back out. How many horses are standing in the field?
Write a program in Visual Basic to find out how many horses are standing in the field.
Write a program in Visual Basic to find out how many horses are standing in the field.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare variables
Dim I, O, B, horses As Integer
'Set values
O = 33
I = 15
B = 7
horses = O - I + B
'Display results
MessageBox.Show("There are " & horses & " horses in the field.")
End Sub
End Class
Friday, January 28, 2011
Word Problem 3 - Apples and Oranges
Ole has 15 apples and 12 oranges. How many pieces of fruit does he have?
Write a program in Visual Basic to display the number of pieces of fruit Ole has.
Write a program in Visual Basic to display the number of pieces of fruit Ole has.
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declare variables
Dim A, O, fruit As Integer
'Set values
A = 15
O = 12
fruit = A + O
'Display results
MessageBox.Show("Ole has " & fruit & " pieces of fruit.")
End Sub
End Class
Subscribe to:
Posts (Atom)