On Sep 3, 11:29 am, Mike <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I need to interface with a couple of Views in Microsoft SQL Server
> 2000. How do I go about doing this with SqlAlchemy? Since a View
> doesn't have columns per se, how do I go about creating a class and a
> table object to map them?
>
> I tried my Google-Fu, but there's not much out there on this subject.
> The SqlAlchemy wiki / bug list seems to have some information, but
> that looks kind of sketchy. Any advice would be appreciated.
>
> I am using Python 2.5.2 with SA 0.5.0beta3
>
> Thanks!
>
> Mike

Replying to my own message seems kind of schizo, but I found one
solution. I reflected the view into a Table() object and then used the
"select" method along with "and_" and "not_". I would prefer to use
the session object, but this works.

I'm currently converting the following SQL:

SELECT LNAME, FNAME, NETNAME
FROM MyView
WHERE (DEPT = '%s') AND (NETNAME <> '')

I then access it like this:

<code>

engine = create_engine('mssql://user:[EMAIL PROTECTED]/DB')
meta = MetaData(engine)
emp_tbl = Table('MyView', meta, autoload=True)
s = select([emp_tbl.c.LNAME,
            emp_tbl.c.FNAME,
            emp_tbl.c.NETNAME],
           and_(emp_tbl.c.HOME_DEPT==deptNum, not_(emp_tbl.c.NETNAME=="")))
res = engine.execute(s)
row = res.fetchall()

</code>

Is there a less messy way to accomplish this? (Yes, I am a SQL newb!)

Mike
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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