Архив метки: CURSOR

MSSQL Пример цикла по результатам запроса

DECLARE @mesto  varchar(30);  
DECLARE c CURSOR FOR SELECT mesto from MyPlaces
OPEN c
FETCH NEXT FROM c INTO @mesto
WHILE @@FETCH_STATUS = 0
BEGIN
      select 'Здесь ' + @mesto
      FETCH NEXT FROM c INTO @mesto
END
CLOSE c
DEALLOCATE c

Python подключение к базе данных MSSQL

import pyodbc
cnxn = pyodbc.connect("Driver={SQL Server};"
                      "Server=srvmssql;"
                      "Database=mydatabase;"
                      "Trusted_Connection=yes;")
cursor = cnxn.cursor()
cursor.execute('SELECT TOP 10 * FROM MYTABLE')
for row in cursor:
    print('row = %r' % (row,))
input()