sql query find match
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Geoff Hayes
on 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 Comments
More Answers (0)
See Also
Categories
Find more on Database Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!