请协助用@MWHERE填写select语句 [英] Please assist to complete the select statement with @MWHERE
问题描述
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
推荐答案
1)不要SH OUT。使用所有大写字母被认为是在互联网上大喊大叫,粗鲁(使用所有小写字母被认为是幼稚的)。如果你想被认真对待,请使用适当的大写字母。
2)首先试着找出问题所在:记住我们不知道SELECT语句是什么应该做什么,或任何访问你的数据库,以找出它可能正在做什么。
但有一些奇怪的地方:
1) DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously.
2) Start by trying to find out what the problem is: remember that we have no idea what the SELECT statement is supposed to do, or any access to your DB to find out what it might be doing.
But there are some oddities there:
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语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!