06. oktober 2005 - 08:37Der er
7 kommentarer og 1 løsning
SQL fejl med Ambiguous
jeg har nedenstående sql men får fejl. fejlen er indsat under sql. Er der nogen der ved hvorfor ?
"SELECT * FROM dbo.tblInjury, dbo.tblEmployee WHERE dbo.tblInjury.CivilRegistrationNumber = dbo.tblEmployee.CivilRegistrationNumber AND (DateOfInjury between '" & ConvertToSqlDate(Request.Querystring("startdate")) & "' AND '" & ConvertToSqlDate(Request.Querystring("enddate")) & "') AND (SickDays between '" & (Request.Querystring("min")) & "' AND '" & (Request.Querystring("max")) & "') "
fejl: Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Ambiguous column name 'CivilRegistrationNumber'.
/reports/include/injury_occupationalinjury.asp, line 50
Teknologi, AI og forretning er i centrum på Computerworlds Cloud og AI Festival i København d. 18. og 19. september. Se hele programmet for den store konference om strategisk brug af Cloud og AI på: www.cloud-festival.dk
CivilRegistrationNumber findes i begge tabeller. Jeg har forsøgt at sætte de værdier ind jeg skal bruge, men det virker heller ikke. Burde den ikke være ok når jeg skriver: dbo.tblInjury.CivilRegistrationNumber = dbo.tblEmployee.CivilRegistrationNumber
tsk_sql = "SELECT dbo.tblInjury.DateOfInjury,dbo.tblInjury.injurynatureID,dbo.tblInjury.injurypartID,dbo.tblEmployee.jobpositionID,dbo.tblEmployee.nationalityID,dbo.tblEmployee.jobtypeID,dbo.tblEmployee.vesselterminalID,dbo.tblEmployee.CivilRegistrationNumber FROM dbo.tblInjury, dbo.tblEmployee WHERE dbo.tblInjury.CivilRegistrationNumber = dbo.tblEmployee.CivilRegistrationNumber AND (DateOfInjury between '" & ConvertToSqlDate(Request.Querystring("startdate")) & "' AND '" & ConvertToSqlDate(Request.Querystring("enddate")) & "') AND (SickDays between '" & (Request.Querystring("min")) & "' AND '" & (Request.Querystring("max")) & "') "
tsk_sql = "SELECT * WHERE dbo.tblInjury.CivilRegistrationNumber = dbo.tblEmployee.CivilRegistrationNumber AND (DateOfInjury between '" & ConvertToSqlDate(Request.Querystring("startdate")) & "' AND '" & ConvertToSqlDate(Request.Querystring("enddate")) & "') AND (SickDays between '" & (Request.Querystring("min")) & "' AND '" & (Request.Querystring("max")) & "') "
If Request.QueryString("vesselterminal")<>"" Then tsk_sql = tsk_sql & "AND vesselterminalID = " & Request.QueryString("vesselterminal") & " " End if If Request.QueryString("jobposition")<>"" Then tsk_sql = tsk_sql & "AND jobpositionID = " & Request.QueryString("jobposition") & " " End if If Request.QueryString("injuryplace")<>"" Then tsk_sql = tsk_sql & "AND injuryplaceID = " & Request.QueryString("injuryplace") & " " End if If Request.QueryString("injurynature")<>"" Then tsk_sql = tsk_sql & "AND injurynatureID = " & Request.QueryString("injurynature") & " " End if If Request.QueryString("injurypart")<>"" Then tsk_sql = tsk_sql & "AND injurypartID = " & Request.QueryString("injurypart") & " " End if tsk_sql = tsk_sql & "ORDER BY " & Request.QueryString("orderby") & " ASC"
Set rsResults = Server.CreateObject("ADODB.Recordset") rsResults.ActiveConnection = MM_claims_conn_STRING tsk_sql = "SELECT * FROM dbo.tblInjury LEFT JOIN dbo.tblEmployee ON dbo.tblInjury.CivilRegistrationNumber = dbo.tblEmployee.CivilRegistrationNumberE "
If Request.QueryString("vesselterminal")<>"" Then tsk_sql = tsk_sql & "AND vesselterminalID = " & Request.QueryString("vesselterminal") & " " End if If Request.QueryString("jobposition")<>"" Then tsk_sql = tsk_sql & "AND jobpositionID = " & Request.QueryString("jobposition") & " " End if
tsk_sql = tsk_sql & "WHERE (DateOfInjury between '" & ConvertToSqlDate(Request.Querystring("startdate")) & "' AND '" & ConvertToSqlDate(Request.Querystring("enddate")) & "') "
If Request.QueryString("min")<>"0" Then tsk_sql = tsk_sql & "AND (SickDays between '" & (Request.Querystring("min")) & "' AND '" & (Request.Querystring("max")) & "') " Else If Request.QueryString("max")<>"999" Then tsk_sql = tsk_sql & "AND (SickDays between '" & (Request.Querystring("min")) & "' AND '" & (Request.Querystring("max")) & "') " End if End if
If Request.QueryString("injuryplace")<>"" Then tsk_sql = tsk_sql & "AND injuryplaceID = " & Request.QueryString("injuryplace") & " " End if If Request.QueryString("injurynature")<>"" Then tsk_sql = tsk_sql & "AND injurynatureID = " & Request.QueryString("injurynature") & " " End if If Request.QueryString("injurypart")<>"" Then tsk_sql = tsk_sql & "AND injurypartID = " & Request.QueryString("injurypart") & " " End if tsk_sql = tsk_sql & "ORDER BY " & Request.QueryString("orderby") & " ASC"
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.