Hi all,

I've been banging my head against the wall on this one for about a day
and a half.  I pinged the IRC channel and they told me to use a sub-
query, but I can't seem to get the code right. I hope someone here can
give me a clue:

Here's the original SQL I'm trying to convert to SA:

<sql>

SELECT
 Checks.CHK_DOC_NO,
 Checks.EMP_ID,
 Checks.CHECK_DATE,
 Checks.CHECK_NO,
 Checks.CHECK_AMT,
 Checks.STATUS,
 Checks.PAY_PERIOD,
 Checks.DIRECT_DEPOSIT,
 NetNames.NETNAME
FROM
 myDB.dbo.ESYCHKHH Checks INNER JOIN
 (SELECT KEY1 AS EMP_ID, UDFVALUE AS NETNAME FROM myDB.dbo.ESXUDFDD
WHERE UDF_ID = 24 and UDFVALUE='plz') NetNames ON Checks.EMP_ID =
NetNames.EMP_ID
ORDER BY Checks.PAY_PERIOD DESC

</sql>

And here's what I have so far:

<code>

netnames = session.query(UserDefined.KEY1,
                         UserDefined.UDFVALUE
                         ).filter(and_(UserDefined.UDF_ID==24,
 
UserDefined.UDFVALUE=="username")).subquery()

qry = session.query(CheckHistory.CHK_DOC_NO,
                    CheckHistory.EMP_ID,
                    CheckHistory.CHECK_DATE,
                    CheckHistory.CHECK_NO,
                    CheckHistory.CHECK_AMT,
                    CheckHistory.STATUS,
                    CheckHistory.PAY_PERIOD,
                    CheckHistory.DIRECT_DEPOSIT,
                    netnames.c.UDFVALUE
                    )

myJoin = join(CheckHistory,
              netnames,
              CheckHistory.EMP_ID == netnames.c.EMP_ID)

qry = qry.select_from(myJoin).filter
(CheckHistory.EMP_ID==netnames.c.EMP_ID)
result = qry.order_by(CheckHistory.PAY_PERIOD).all()

</code>

It throws an exception on the first qry:

TypeError: 'Alias' object is unindexable

I don't really know why it's giving me that. I can call
"netnames.c.UDFVALUE" on the command line and it returns...albeit with
this weird stuff:

Column(u'UDFVALUE', MSChar(collation=u'SQL_Latin1_General_CP1_CI_AS',
length=60), table=<%(23283536 anon)s>)

I am running this against reflected MS SQL Server 2000 tables on
Windows XP with SA 0.5.4p2 and Python 2.5. Thank you for you time!

Mike
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to