tags:

views:

28

answers:

0

Hi All,

Currently I'm talking to a MS SQLServer using 'Microsoft SQL Server Management Studio Express'. I would like to execute the scripts written using 'Microsoft SQL Server Management Studio Express' from the python environment.

For this, I have connected to the MS SQLServer using pymssql but I'm finding translating the existing SQL code to the python environment difficult e.g. multiple JOIN statements and DATECAST etc.

Is there an easier way to reuse the existing SQL code? Here is an example of the code i'm struggling with:

DECLARE @date1 datetime, @date2 datetime
SET DATEFORMAT DMY
SET @date1 = CAST('11/10/2010' AS DATETIME)
SET @date2 = CAST('16/10/2010' AS DATETIME)
SELECT cat AS 'Lot'
FROM tblCat AS MTL2
   JOIN tblCattle AS PSM ON PSM.mtPK = MTL2.mtlPK
   WHERE PSM.pscClass = 'cattle' 
   ORDER BY 'Material Lot ID' DESC

Thank you

Anon