MSSQL LIKE and IN statements in ADO problem

Michael.Coll-Barth at Michael.Coll-Barth at
Wed Jan 18 12:24:53 EST 2006


This seems to work just fine for me...

>>> name = '%raj%'
>>> test = "SELECT * FROM tb_name WHERE firstname LIKE '%s'" % name
>>> print test
SELECT * FROM tb_name WHERE firstname LIKE '%raj%'

-----Original Message-----
From: at
[ at pytho]On Behalf Of gregarican
Sent: Wednesday, January 18, 2006 11:34 AM
To: python-list at
Subject: Re: MSSQL LIKE and IN statements in ADO problem

Can't you get rid of the Create Parameter part and directly pass along
the value you are looking for? Something like...

name = 'raj'
cmd.CommandText= \
        "SELECT * FROM tb_name WHERE firstname LIKE %%%s" % name

This way the value of the name variable gets passed along when the
CommandText method is invoked. BTW, this looks too painfully much like
Visual Basic than Python :-) Just kidding (kind of)


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

More information about the Python-list mailing list