MSSQL LIKE and IN statements in ADO problem

ram0812 at hotmail.com ram0812 at hotmail.com
Wed Jan 18 10:26:58 EST 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.Parameters.Append(p)
        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
            rs.MoveNext()
        rs.Close()

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