>SQL Server 2005
>Table1:
>
>field1 c(6)
>field2 c(6)
>
>SQL Server 2005
>Table2:
>
>field1 c(6) && same value as table1.field1 (case may or may not be the same)
>field2 c(4) && filter condition this value must equal "CHTY" to get selected
>field3 c(40) && same value as table2.field2 (case/len may or may not match)
>field4 T && Datetime field
>
>I want to select from table2 WHERE :
>
>lower(alltrim(table2.field1))==lower(alltrim(table1.field1))
>table2.field2 == "CHTY"
>lower(alltrim(table2.field3))==lower(alltrim(table1.field2))
>
>and then only the most recent 5 records in table2 based on the datetime field of table2.field4
>
>I just can't seem to get it right today...
>
>Any ideas?
>TIA!
Is this works?
SELECT TOP 5 * FROM Table2;
INNER JOIN Table1 ON lower(table2.field1)==lower(table1.field1) AND;
lower(table2.field3)==lower(table1.field2)
WHERE table2.field2 == "CHTY"
ORDER BY field4 DESC
you could use RTRIM(LTRIM()) to simulate alltrim, but I prefer to use varchar() :o)))
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.