2013-02-16 110 views
0

我有這兩個查詢,我不知道如何將它們連接在一起。 這裏是:加入兩個內部連接查詢

command.CommandText = " 
    SELECT sl.Reg_No,sr.ID_Number,sr.Name,sr.Course,sl.Date,sl.Time_IN,sl.Time_Out,sl.ScheduleId 
    FROM student_logs sl 
     INNER JOIN student_records sr ON sl.Student_Reg_No=sr.Reg_No 
    WHERE sl.date between '" & fromDateTimePicker.Value.ToShortDateString & "' and '" & toDateTimePicker.Value.ToShortDateString & "' 
    ORDER BY Reg_No DESC"; 

command.CommandText = " 
    SELECT sls.StudentLogStatusDescription 
    FROM studentlogstatus sls 
     INNER JOIN student_logs sl ON sls.StudentLogStatusId=sl.StudentLogStatusId 
    ORDER BY Reg_No DESC"; 

非常感謝您的幫助。

回答

1

您可以在一份聲明中不止一個加入,讓你可以結合兩個語句獲得:

command.CommandText = 
    "SELECT sl.Reg_No,sr.ID_Number,sr.Name,sr.Course,sl.Date, 
     sl.Time_IN,sl.Time_Out,sl.ScheduleId,sls.StudentLogStatusDescription 
    FROM student_logs sl 
     INNER JOIN student_records sr ON sl.Student_Reg_No=sr.Reg_No 
     INNER JOIN studentlogstatus sls 
       ON sls.StudentLogStatusId=sl.StudentLogStatusId 
    WHERE sl.date between '" & fromDateTimePicker.Value.ToShortDateString & 
        "' and '" & toDateTimePicker.Value.ToShortDateString & "' 
    ORDER BY Reg_No DESC"; 
+0

感謝爵士。它幫助了很多:) – 2013-02-16 17:04:09