sql query find match

3 visualizzazioni (ultimi 30 giorni)
mark
mark il 31 Gen 2015
Risposto: Geoff Hayes il 1 Feb 2015
hello guys, can you help me? how can i prevent adding same information in the database using sql query?
this is my code
cname= get(c_name,'string');
conn = database('mydatabase_2','','')
curs = exec(conn,'select * from db1');
curs = fetch(curs);
curs.Data
sqlquery = ['select * from db1 '...
'where cname = ' cname ];

Risposta accettata

Geoff Hayes
Geoff Hayes il 1 Feb 2015
Mark - I suspect that your query could be more like
sqlquery = ['select count(*) from db1 '...
'where cname = ''' cname '''' ];
Note that since the name is a string, you should wrap it in quotes. For example, if cname were Mark, then the above SQL query would become
sqlquery =
select count(*) from db1 where cname = 'Mark'
Note that we use count to determine the number of records in the database that match on the name Mark. You could then execute this query as
curs = exec(conn,sqlquery);
curs = fetch(curs);
curs.Data
where curs.Data would be an integer value that you would use to determine whether you should add the information to the database (if zero) or not (if non-zero).

Più risposte (0)

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by