Author |
Topic |
ann
Posting Yak Master
220 Posts |
Posted - 2011-05-03 : 10:03:58
|
Table: LoansLoanID, Sent, Dept, EmployeeFlag1, 12/02/2010, A, 02, 12/03/2010, B, 03, 12/04/2010, 0Table: NotesNoteID, LoanID, DateTime, Category1, 1, 01/03/2011 11:47:00, NULL2, 1, 01/04/2011 11:50:00, C3, 1, 01/04/2011 11:55:00, B4, 2, 01/04/2011 11:58:00, AWanted Result:LoanID, Sent, dept1, 12/02/2010, AObjective, Get the results of Loans if the earliest/first Note for that loan where the note category is not nullQuery I am using without success:select LoanID, sent, Dept from Loans where EmployeeFlag = 0 and exists(SELECT MIN(DateTime) FROM tblNotesWhere LoanID = tblloans.loanID and category is not null )Error Msg:Syntax error converting character string to smalldatetime data type. The DateTime in Notes is a column of datatype smalldatetimeAny help appreciated - thanks |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-05-03 : 10:27:23
|
[code]select *from( select l.LoanID, l.Sent, l.Dept, n.category, row_no = row_number() over (partition by l.LoanID order by n.DateTime) from Loans l inner join tblNotes n on l.LoanID = n.LoanID where l.EmployeeFlag = 0) lwhere l.row_no = 1and l.category is null[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
ann
Posting Yak Master
220 Posts |
Posted - 2011-05-03 : 10:36:24
|
Thank you, but I'm getting the following error:'row_number' is not a recognized function name? |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-05-03 : 10:51:10
|
are you using SQL 2005 ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
ann
Posting Yak Master
220 Posts |
Posted - 2011-05-03 : 11:02:55
|
I'm actually testing on a 2000 - I'll try on a 2005Thank you |
 |
|
|
|
|