python 如何使用源生sql语句查询多个参数的情况

2025-12-13 02:26:47
推荐回答(1个)
回答1:

# coding: utf-8
# an example
"""
-- the SQL Server storage process:
drop procedure proc_getconflist 
go
create procedure proc_getconflist 
      @customer char(6)
    , @servicekey varchar(16) = NULL 
    , @dt_bgn datetime = NULL 
    , @dt_end datetime = NULL 
as begin
    select billsumidx as idx
    from conf_billsum
    where 1=1
    and sumtypeid=1
    and isnull(@customer, customercode) = customercode
    and isnull(@servicekey, servicekey) = servicekey
    and isnull(@dt_bgn, begintime) < endtime
    and begintime < isnull(@dt_end, endtime)
end
go

"""

import pymssql

conn = pymssql.connect(
        host="192.168.70.7",
        user='pyquery',
        password='Qpery',
        database='gb201412',
        )
curr = conn.cursor()
curr.execute("exec proc_getconflist %s, %s, %s, %s",
        ('990003', None, None, None))
for idx, in curr:
    print idx
curr.close()
conn.close()