pymssql を使用してデータタイム オブジェクトを挿入するにはどうすればよいですか? SQL Server テーブルが datetime オブジェクトを予期していることはわかっています。たとえば、位置 3 で考えてみましょう。これらの 3 つすべてを試しました。
cursor.execute("INSERT INTO MyTable VALUES(1, 'Having Trouble', datetime.datetime.now())")
cursor.execute("INSERT INTO MyTable VALUES(1, 'Having Trouble', 20130410)")
cursor.execute("INSERT INTO MyTable VALUES(1, 'Having Trouble', '20130410')")
cursor.execute("INSERT INTO MyTable VALUES(1, 'Having Trouble', GETDATE())")
毎回同じエラーが発生します。
OperationalError: (241, 'Conversion failed when converting date and/or time from character string.DB-Lib error message 241, severity 16:\nGeneral SQL Server error: Check messages from the SQL Server\n')
そこにある小さなドキュメントを精査し、繰り返し検索しました。
編集:二次的な問題はフィールド長の問題でした。受け入れられた回答の最初のコメントを参照してください。