本文介绍了如果是sql server中的else语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! CREATE PROCEDURE [dbo]。[K_FS_Test] @ fromdate datetime , @todate datetime , @ customertype varchar ( 50 ), @ customername varchar ( 50 ) AS if (选择 Orderno 来自 k_Fs_orderdetails 其中 attrited = ' false') BEGIN SET NOCOUNT ON ; 选择 orderno 来自 K_FS_OrderDetails 其中 attrited = ' false' AND 个客户类型 ( @ customertype )和 customername in ( @ customername ) 和 ordereddate @ fromdate 和 @ todate order by orderno desc END ELSE BEGIN 选择 orderno 来自 K_FS_OrderDetails 其中 attrited = ' TRUE' > customertype ( @ customertype )中的代码关键字>和 customername ( @ customername ) @ fromdate 和 ordereddate code-keyword>和 @ todate order by orderno desc END 请更正这个程序... 解决方案 如果orderno ='love' if ((选择 Orderno 来自 k_Fs_orderdetails 其中 attrited = ' false' )= ' love') 总是在你的问题中包含错误信息以获得快速答案。 IIRC你应该使用下面的条件( IF EXISTS ) IF EXISTS (选择 Orderno 来自 k_Fs_orderdetails 其中 attrited = ' fa lse') 查看此示例以获取简单示例 删除存储过程(如果存在于SQL Server中) [ ^ ] OR获取变量中的值(第一个SELECT查询结果),使用IF条件创建条件 小心处理大小写的事情。是的,你为什么要使用'假'和& '真正'。对两个值使用小写或大写。我建议你在查询中使用函数 UPPER / LOWER 来获得正确的结果集。 CREATE PROCEDURE [dbo].[K_FS_Test]@fromdate datetime, @todate datetime, @customertype varchar(50), @customername varchar(50)ASif(select Orderno from k_Fs_orderdetails where attrited = 'false')BEGINSET NOCOUNT ON;select orderno from K_FS_OrderDetails where attrited = 'false' AND customertype in (@customertype) and customername in (@customername) and ordereddate between @fromdate and @todateorder by orderno descENDELSEBEGINselect orderno from K_FS_OrderDetails where attrited = 'TRUE' AND customertype in (@customertype) and customername in (@customername) and ordereddate between @fromdate and @todateorder by orderno desc ENDPlease correct this procedure... 解决方案 if orderno='love'if((select Orderno from k_Fs_orderdetails where attrited = 'false')='love')Always include the error message in your question to get quick answers.IIRC you should use the condition like below(IF EXISTS)IF EXISTS(select Orderno from k_Fs_orderdetails where attrited = 'false')Check this one for simple exampleDrop Stored Procedure if exist in SQL Server[^]OR get the value(first SELECT query result) in a variable, use IF condition for that to create conditionsAnd careful with case sesitive things. Yes, why are you using 'false' & 'TRUE'. Use either lowercase or UPPERCASE for both values. I recommend you to use functions UPPER/LOWER in your query to get right resultset. 这篇关于如果是sql server中的else语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!