MATLAB is not passing string type variable into SQL SERVER 2014

abc = 'abcdef';
conn = database('databasename','user id','password',...
'Vendor','Microsoft SQLServer', 'Server', '(local)', 'AuthType', 'Server', 'portnumber', 1433);
query = 'INSERT INTO table_Name (column_Name) VALUES (abc)';
curs = exec(conn,query );
close(curs);
close(conn);

 Respuesta aceptada

query = sprintf( 'INSERT INTO table_Name (column_Name) VALUES (''%s'')', abc);

2 comentarios

its working. thanks alot :-)
%s is a string format specifier for the sprintf() call. sprintf() is like fprintf() but returns the output to a string.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 10 de Mzo. de 2016

Comentada:

el 12 de Mzo. de 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by