Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 如何在IF语句中进行区分大小写的匹配_Sql Server_Tsql - Fatal编程技术网

Sql server 如何在IF语句中进行区分大小写的匹配

Sql server 如何在IF语句中进行区分大小写的匹配,sql-server,tsql,Sql Server,Tsql,我在做一个IF语句,想要一个精确匹配 IF ( @a_Action <> 'Power On' AND @a_Action <> 'Power Off' AND @a_Action <> 'Reset' ) BEGIN -- Invalid action - an IPMI command. -- Set call as failed. SELECT @ErrorSw = 'Y' SELECT @ApiResultOut =

我在做一个IF语句,想要一个精确匹配

IF ( @a_Action <> 'Power On' AND @a_Action <> 'Power Off' AND @a_Action <> 'Reset' )
BEGIN
    -- Invalid action - an IPMI command. 
    -- Set call as failed.
    SELECT @ErrorSw = 'Y'
    SELECT @ApiResultOut = 0
    SELECT @ApiResultCodeOut = 1610
    SELECT @ApiMessageOut = 'Warning - action type "' + @a_Action + '" is not a valid server (IPMI) command.'
END
IF(@a_Action“开机”和@a_Action“关机”和@a_Action“复位”)
开始
--无效操作-IPMI命令。
--将调用设置为失败。
选择@ErrorSw='Y'
选择@ApiResultOut=0
选择@ApiResultCodeOut=1610
选择@ApiMessageOut='警告-操作类型“++@a_action+'”不是有效的服务器(IPMI)命令。'
结束
如果@a_Action参数以“开机”的形式发送进来,它将通过而不会出错。只有精确的匹配才能通过

DECLARE @a_Action VARCHAR(20)
SET @a_Action = 'Power on' COLLATE SQL_Latin1_General_CP1_CS_AS

IF (@a_Action = 'Power On' COLLATE SQL_Latin1_General_CP1_CS_AS)
    PRINT 'match'
ELSE
    PRINT 'not match'
DECLARE @A varchar(10) = 'Power on' 

IF @A COLLATE SQL_Latin1_General_CP1_CI_AS NOT IN ( 'Power On', 'Power Off', 'Reset' ) 
BEGIN
    Print 'Invalid command'
END
ELSE
BEGIN
    PRINT 'OK command'
END ;