如果是sql server中的else语句 [英] If else statement in sql server

查看:112
本文介绍了如果是sql server中的else语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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 < span class =code-keyword> in ( @ customername
ordereddate @ fromdate @ todate
order by orderno < span class =code-keyword> 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'


< blockquote>总是在你的问题中包含错误信息以获得快速答案。



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)
	
AS
if(select Orderno from k_Fs_orderdetails where attrited = 'false')

BEGIN
      	
	
	SET NOCOUNT ON;
select orderno from K_FS_OrderDetails where attrited = 'false' AND customertype in (@customertype) and customername in (@customername)
 and ordereddate between @fromdate and @todate
order by orderno desc 
   
END
ELSE	
	BEGIN
	
	select orderno from K_FS_OrderDetails where attrited = 'TRUE' AND customertype in (@customertype) and customername in (@customername)
 and ordereddate between @fromdate and @todate
order by orderno desc 
   
   END



Please 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 example
Drop 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 conditions

And 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语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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