1

我不知道如何在 matlab 中将日期传递给我的 sql 查询。当我“静态地”这样做时,它工作得非常好:

myquery1 = ['Select DeliveryMonth, Value '...
 ' FROM [mydatabase] '...
 ' where idcurve = 33 ' ...
 ' and deliverymonth <''20121130'' '...
  ' order by DeliveryMonth ']

但我想要的是这样的:

breakdate = input('Enter a breakdate as 20121130: ', 's')

myquery1 = ['Select DeliveryMonth, Value '...
 ' FROM [mydatabase] '...
 ' where idcurve = 33 ' ...
 ' and deliverymonth <   ''breakdate'' '...
  ' order by DeliveryMonth ']

问候A

4

2 回答 2

1

您缺少一个单引号:

breakdate = '20121130'
myquery1 = ['Select DeliveryMonth, Value '...
 ' FROM [mydatabase] '...
 ' where idcurve = 33 ' ...
 ' and deliverymonth < '''breakdate''' '...
  ' order by DeliveryMonth ']

返回:

myquery1 =

Select DeliveryMonth, Value  FROM [mydatabase]  where idcurve = 33  and deliverymonth < '20121130'  order by DeliveryMonth 
于 2013-10-17T15:57:07.077 回答
0
 ' and deliverymonth < '  + breakdate + ...
于 2013-10-17T15:34:27.983 回答