本文介绍了请协助用@MWHERE填写select语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL SERVER 2008.



请协助完成@MWHERE以下的选择声明









IF @CDCOMPT<>'ALL'

BEGIN

SET @ MWHERE = @ MWHERE +'AND A.COMP_TYPE=@CDCOMPT'

END

ELSE

IF @CDCOMPT ='ALL'

BEGIN

SET @ MWHERE = @ MWHERE

END

----------- ------------------------

------ COMPLAINT_TYPE ----------- ----

-----------------------------------



SELECT * FROM RESPONSE A

LEFT JOIN BRANCH C

ON A.BRN_NAME = C.BRN_NAME

LEFT JOIN PAYMAST B

ON A.LNAME +''+ A.FNAME +''+ A.EMPNO = B.LNAME +''+ B.FNAME +''+ B.EMPNO

& @MWHERE



我尝试过:



这些代码我需要帮助来纠正

SQL SERVER 2008.

PLEASE ASSIST TO COMPLETE THE SELECT STATEMENT BELOW WITH @MWHERE




IF @CDCOMPT <>'ALL'
BEGIN
SET @MWHERE=@MWHERE+'AND A.COMP_TYPE=@CDCOMPT'
END
ELSE
IF @CDCOMPT ='ALL'
BEGIN
SET @MWHERE=@MWHERE
END
-----------------------------------
------COMPLAINT_TYPE---------------
-----------------------------------

SELECT * FROM RESPONSE A
LEFT JOIN BRANCH C
ON A.BRN_NAME = C.BRN_NAME
LEFT JOIN PAYMAST B
ON A.LNAME+''+A.FNAME+''+A.EMPNO= B.LNAME+''+B.FNAME+''+B.EMPNO
&@MWHERE

What I have tried:

These are codes which I need help to correct

推荐答案

SET @MWHERE=@MWHERE

什么都不做。

所以这段代码是完全冗余的:

Does nothing.
So this code is completely redundant:

IF @CDCOMPT ='ALL' 
BEGIN 
SET @MWHERE=@MWHERE 
END



此代码可能使用空格:


And this code could probably use a space:

SET @MWHERE=@MWHERE+'AND A.COMP_TYPE=@CDCOMPT'

尝试:

Try:

SET @MWHERE=@MWHERE+' AND A.COMP_TYPE=@CDCOMPT'

和&是一个SQL Bitwise运算符,在应用于字符串时会给出错误:

And "&" is an SQL Bitwise operator and will give you an error when applied to strings:

ON A.LNAME+''+A.FNAME+''+A.EMPNO= B.LNAME+''+B.FNAME+''+B.EMPNO
&@MWHERE

可能你正在尝试构建一个命令,这意味着你需要+,但是你必须将整个命令构建成一个字符串并使用EXEC来运行它。

Probably you are trying to build a command, which implies you need "+" instead, but then you would have to build the whole command into a string and use EXEC to run it.


这篇关于请协助用@MWHERE填写select语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 00:53