一个简单的SQL问题和错误 [英] A simple sql question and error

查看:77
本文介绍了一个简单的SQL问题和错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试执行时,此代码给出错误

 创建  Proc  spIsPasswordResetLinkValid 
@ GUID uniqueidentifier
< span class =code-keyword> as
开始
如果存在选择 UserId 来自 tblResetPasswordRequests 其中 Id = @ GUID)
开始
选择 1 as IsValidPasswordresetLink
结束
否则
开始
Sel ect 0 as IsValidPasswordResetLink
结束
结束



它给出的错误

消息156,级别15,状态1,过程spIsPasswordResetLinkValid,第7行
关键字Begin附近的语法不正确。

消息156,等级15,状态1,过程spIsPasswordResetLinkValid,行10
关键字'Else'附近的语法不正确。



我不知道错误是什么。有人能指出我正确的方向。

解决方案

括号不匹配。试试这个:

 如果 存在 tblResetPasswordRequests选择 UserId  其中 Id = @ GUID)





编辑

我觉得你的代码也是如此程序。用SQL来避免这种情况会更好。此外,通常不建议在数据库中使用逻辑。您应该只查询数据,例如:

 选择计数(UserId)来自 tblResetPasswordRequests 其中​​ Id = @ GUID 



然后评估结果application。


你在这里缺少一个括号

 If(存在(选择UserId 来自 tblResetPasswordRequests 其中 Id = @ GUID)





尝试添加像[/ b> b la lang =c#>如果(存在(从 tblResetPasswordRequests ) -sdkkeyword>其中​​ Id = @ GUID))



希望,它有帮助:)


This code gives me error when i try to execute

Create Proc spIsPasswordResetLinkValid
@GUID uniqueidentifier
as
Begin
   If(Exists(Select UserId from tblResetPasswordRequests where Id =@GUID)   
   Begin 
     Select 1 as IsValidPasswordresetLink
   End
   Else
   Begin
      Select 0 as IsValidPasswordResetLink
   End
End


The error it gives

Msg 156, Level 15, State 1, Procedure spIsPasswordResetLinkValid, Line 7
Incorrect syntax near the keyword 'Begin'.

Msg 156, Level 15, State 1, Procedure spIsPasswordResetLinkValid, Line 10
Incorrect syntax near the keyword 'Else'.


I dont know whats the error. Can someone point me to right direction.

解决方案

Parenthesis do not match. Try this:

If Exists(Select UserId from tblResetPasswordRequests where Id =@GUID)



Edit
It occurs to me that your code is too procedural. It's better you avoid that with SQL. Moreover having logic in database is usually not recommended. You should simply query the data e.g.:

Select count(UserId) from tblResetPasswordRequests where Id =@GUID


and then evaluate the result in your application.


You are missing a bracket here

If(Exists(Select UserId from tblResetPasswordRequests where Id =@GUID)



Try adding an end braket like

If(Exists(Select UserId from tblResetPasswordRequests where Id =@GUID))


Hope, it helps :)


这篇关于一个简单的SQL问题和错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆