1

I can't figure out how to pass a date to my sql query in matlab. When I do it "statically" it workds perfectly well:

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

But what I want is this:

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

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

regards A

2 Answers 2

1

You are missing a single quote mark:

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

which returns:

myquery1 =

Select DeliveryMonth, Value  FROM [mydatabase]  where idcurve = 33  and deliverymonth < '20121130'  order by DeliveryMonth 
Sign up to request clarification or add additional context in comments.

2 Comments

checking myquery1 it just retursn ...deliverymonth < 'breakdate'... There must be some conversion problems somewhere.
Ok, so I solved this by using a great GUI from mathworks at mathworks.com/matlabcentral/fileexchange/8313-uigetdate/content/… and then changing my code to myquery1 = ['Select DeliveryMonth, Value '... ' FROM [ENOI_INDICI].[dbo].[v_mdm_MCurves] '... ' where idcurve = 33 '... ' and deliverymonth <',' ''',datestr(breakdate,29),' '''... ' order by DeliveryMonth ']
0
 ' and deliverymonth < '  + breakdate + ...

1 Comment

Sorry no doesn't work. ahve tried this: ' and deliverymonth <',' ''breakdate '' '... which doesn't give any errors but also does not return any data...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.