在matlab中将日期传递给sql查询

时间:2013-10-17 15:29:43

标签: sql matlab user-input

我无法弄清楚如何在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 ']

问候 甲

2 个答案:

答案 0 :(得分: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 

答案 1 :(得分:0)

 ' and deliverymonth < '  + breakdate + ...