Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
sql query-passing variable error

Subject: sql query-passing variable error

From: kainat ali

Date: 20 Feb, 2013 07:55:03

Message: 1 of 4

I'm taking input from user on Command Window and storing that input in a variable (UserInput). After this I'm trying to pass this information to the sql query to select the data from database:

query2 = strcat(strcat('select Column1 from Table where Column2=''', UserInput), '''')
curs1 = exec(conn,query2)
final = fetch(curs1)
final1 = fetch(conn,query2)

The following error comes:

Error using database/fetch (line 37)
Second argument must be either a query string or object of type sqlOutput

Error in recipe (line 23)
   final1 = fetch(conn,query2)

What I understand is that the query2 that its taking, it is taking as a string instead of sql query. What should I do to make it recognize as an sql query instead of a string.
  

Subject: sql query-passing variable error

From: kainat ali

Date: 20 Feb, 2013 08:06:01

Message: 2 of 4

Im using Matlab R2012b.

Subject: sql query-passing variable error

From: Muharrem

Date: 22 Jun, 2013 17:26:21

Message: 3 of 4

Kainat Ali <kainat.ali21@gmail.com> wrote in message <be54c52d-e85f-47dd-bd39-fce4a09617b2@googlegroups.com>...
> Im using Matlab R2012b.

Hi,

Just change the two single quotation characters '' into one double quotation character "
query2 = strcat(strcat('select Column1 from Table where Column2=" ', UserInput), '" ')

or use
query2 = ['select Column1 from Table where Column2="' UserInput '"']

Regards,
Muharrem

Subject: sql query-passing variable error

From: Muharrem

Date: 22 Jun, 2013 17:50:10

Message: 4 of 4

Kainat Ali <kainat.ali21@gmail.com> wrote in message <be54c52d-e85f-47dd-bd39-fce4a09617b2@googlegroups.com>...
> Im using Matlab R2012b.

Hi,

You can use sprintf to create your sql query instead of strcat.

Regards,
Muharrem

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us