Jump to content

packrat

Members
  • Posts

    61
  • Joined

  • Last visited

Everything posted by packrat

  1. Can you select rows from each of the tables individually or is there possibly a naming issue?dBase Sql isn't my primary sql, but it doesn't seem that you should be getting an error based on the syntax.Here's an alternative showing how you can move the filter conditions on conthist into a sub query and simplify the outer where clause.I'm not sure that i've got your logic correct, might require some tweaking.Mostly I'm wondering about the error, let us know if you're able to select from each of the tables individually. SELECT contact1.contact, contact1.address1, contact1.address2, contact1.city, contact1.state, contact1.zip , conthist.ondate, contact1.key3, conthist.resultcode, conthist.accountno, conthist.userid, conthist.recidFROM contact1 INNER JOIN ( SELECT ondate, resultcode, accountno, userid, recid FROM conthist WHERE resultcode NOT IN ('SLE','SLD','SL1','SL2') AND resultcode = 'TNS' AND ondate > GetDate() ) AS conthist ON contact1.accountno = conthist.accountno INNER JOIN Cal ON contact1.accountno = Cal.accountno AND cal.rectype = 'A' WHERE contact1.address1 <> '' OR contact1.city <> '' OR contact1.state <> '' OR contact1.zip <> ''
  2. packrat

    Complex Select

    I've been through quite an ordeal trying to get registered in order to drop you this chunk of sql, ... sure hope it works. Much thanks to the admins for getting me going. Try plugging your variable names into the sql below. I haven't tested this solution, if its buggy I might be able to help. if you get an error in the 'where' try changing the '=' to 'IN'. let me know how it pans out. --answer to complex select SELECT [year], [month], [day]FROM [table] WHERE [table].[year] = ( SELECT TOP 1 [year] FROM [table] WHERE [year]=0 OR [year]=@year GROUP BY [year] HAVING COUNT([year]) > 0 ORDER BY [year] DESC ) AND [table].[month] = ( SELECT TOP 1 [month] FROM [table] WHERE [month]=0 OR [month]=@month GROUP BY [month] HAVING COUNT([month]) > 0 ORDER BY [month] DESC ) AND [table].[day] = ( SELECT TOP 1 [day] FROM [table] WHERE [day]=0 OR [day]=@day GROUP BY [day] HAVING COUNT([day]) > 0 ORDER BY [day] DESC ) //PackRat
×
×
  • Create New...