MSSQL LIKE and IN statements in ADO problem

ram0812 at ram0812 at
Wed Jan 18 16:26:58 CET 2006

Helo guys,
    I am trying to query the MSSQL DB using ADO.
I am not able to make the LIKE statement fetch the correct results.
Can anyone tell me what I need to do to get this working?
Below is the code snippet:

        import win32com.client
        const = win32com.client.constants

        #conn = establish SQL connection
        cmd = win32com.client.Dispatch("ADODB.Command")
        cmd.ActiveConnection = conn

        name = '@fname'
        value = "'raj"
        p=cmd.CreateParameter(name, const.adVarchar, Value=value)
        cmd.CommandText = \
                "SELECT * FROM tb_name WHERE firstname LIKE @fname"
        cmd.CommandType = const.adCmdText
        (rs, dummy) = cmd.Execute()
        while not rs.EOF:
            print rs.Fields('firstname').Value

I originally was using the '%?%' symbol but that did not work and now,
i changed it to @fname but this returns a traceback telling that I need
to declare @fname.

Also, I have another probelm with using the "IN" SQL statement.

I appreciate your help in advance,

Thank you,
Raja Raman

More information about the Python-list mailing list