帮我看看这个sql语句
我正在使用 mysql 和 vb6 来执行此查询。
sql = "select user_id, fname, middle, lname from users where NOT EXISTS (SELECT user_id FROM accounts where accounts.user_id = users.user_id) "
我想做的是从表 users 中获取记录列表,其中 user_id 在表帐户中不存在。我在这方面取得了成功,但是,我的 vb 代码有问题。
我希望在文本框的更改事件上,如果用户键入 1,则将显示所有以 1 开头的记录。我尝试这样做但无济于事..我有语法错误 ..顺便说一下,nuser_id 是文本框的值..
sql = "select user_id, fname, middle, lname from users where NOT EXISTS (SELECT user_id FROM accounts where accounts.user_id = users.user_id) and user_id like'" & nuser_id & "%'"""
有什么想法吗?谢谢..
im using mysql and vb6 to execute this query..
sql = "select user_id, fname, middle, lname from users where NOT EXISTS (SELECT user_id FROM accounts where accounts.user_id = users.user_id) "
what i'm trying to do is to get the list of records from table users where the user_id does not exist on table accounts. i was successful on this, however, im having a problem with my vb code..
i want that on the change event of my textbox, if the user type 1, all the records starting with 1 will be displayed..i tried doing this but to no avail..i got syntax error
..by the way, the nuser_id is the value of text box..
sql = "select user_id, fname, middle, lname from users where NOT EXISTS (SELECT user_id FROM accounts where accounts.user_id = users.user_id) and user_id like'" & nuser_id & "%'"""
any idea? thanks..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
未经测试,但可能有效:
我强烈建议您将变量
nuser_id
转换为整数(或者如果您的 id 不是数字,则通过 sql 转义它)。顺便说一句:您的原始代码在
LIKE
之后泄漏了空格。Not tested but might work:
I strongly suggest, that you cast the variable
nuser_id
to integer (or sql escape it if your ids aren't numbers).Btw: Your original code was leaking a whitespace after the
LIKE
.试试这个:
Try this: