sql query find match
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 ];
0 Commenti
Risposta accettata
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).
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Database Toolbox in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!