SQL Server CASE 1 WHEN 1, WHERE 1=1 AND 1=1 -


I inherited the following queries from the previous application. I'm having a hard time understanding "selection" and "case" in the "Where" section.

  SELECT J1.AC_CODE, J1.PERIOD, J1.JRNAL_NO, J1.DESCRIPTN, - J1.AMOUNT, J1.ANAL_T3, Case 1, when 1AJ, which is 1.ACCNT_CODE END, Deo with J1.JRNAL_LINE JSOs J1 where 1 = 1 and 1 = 1 and not ('A' like '% Z%' and J1.JRNAL_SRCE IN ('B / F', 'CLRDN') and J1.JRNAL_NO = 0) and case 1 When 1 'A' is either J.AC_CODE END = 'A' and J1.AC_CODE = '156320' and J1 Differences between 2014 and 2014012 and J1 NALTH3 = 'Analyam' order 1,2, 3,4,5,6,7,8  

I'm not sure if I understand the following sections correctly:

First section:

  issue 1 when 1 then J1.AC_CODE END  

through A Gone: If column 1 is true, select literal A or else choose J1. AC_CODE

Second section:

  where 1 = 1 and 1 = 1 and not ('A' like '% Z%' and J1.JRNAL_SRCE IN ('B / F', 'CLRDN') and J. JRNLLO = 0) and case 1 when the difference between 1A 'A' JACACOCEDEDED = 'A' and J1AAC_Code = '156320' and J1  P> Can you explain this query and write a better version for this whole query? I am running this query on SQL Server 2008 (R2)  

I understand: If the column 1 is correct, then select literal A or else choose J1.AC_CODE.

No, this value is being compared to 1 with value 1 and if this is true then the case is a A and it is definitely always correct, so the case statement will always return A .

Your section does nothing at all.

  1 = 1 and 1 = 1  

will always be true and the case will always be true and '% Z' Will always be false and this is the whole and not as 'A' like '% Z%' .... As always the expression is true.

A simple version of your query will look like this.

  SELECT J1.AC_CODE, J1.PERIOD, J1.JRNAL_NO, J1.DESCRIPTN, - J1. AMOUNT, J1.ANAL_T3, 'A', J1.JRNAL_LINE to Dbo.JSource J1 WHERE J1.AC_CODE = '156320' and J1. 2014 between 2014001 and 2014012 and J1.ANAL_T3 = 'ANAL001' order 1,2,3,4,5,6,7,8  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -