Logo SQLinForm

 

[started] Need help in formating
September 27, 2010 03:24PM
How do I customize the application to format the following code.

SELECT TbChangeRequest.RequestedDate, Sum(IIf([FkStatus]<>2 And RequestedDate=Date()-1,1,0)) AS [Opened yesterday], Sum(IIf([FkStatus]=2 And RequestedDate=Date()-1,1,0)) AS [Close yesterday], Sum(IIf([FkStatus]<>2 And RequestedDate=Date(),1,0)) AS [Opened today], Sum(IIf([FkStatus]=4,1,0)) AS [Need More Information], Sum(IIf([FkStatus]=1,1,0)) AS [Pending ECN], Sum(IIf([FkStatus]=3,1,0)) AS [Pending-Parts Split]
FROM TbChangeRequest
GROUP BY TbChangeRequest.RequestedDate;


Here the best I can do:

SELECT TbChangeRequest.RequestedDate,
SUM(
IIF([FkStatus]<>2
AND RequestedDate=DATE()-1,1,0)) AS [Opened yesterday],
SUM(
IIF([FkStatus]=2
AND RequestedDate=DATE()-1,1,0)) AS [Close yesterday],
SUM(
IIF([FkStatus]<>2
AND RequestedDate=DATE(),1,0)) AS [Opened today],
SUM(
IIF([FkStatus]=4,1,0)) AS [Need More Information],
SUM(
IIF([FkStatus]=1,1,0)) AS [Pending ECN],
SUM(
IIF([FkStatus]=3,1,0)) AS [Pending-Parts Split]
FROM TbChangeRequest
GROUP BY TbChangeRequest.RequestedDate;

Here what I would like:

SELECT TbChangeRequest.RequestedDate,
SUM(IIF([FkStatus] <> 2 AND RequestedDate = DATE()-1, 1, 0)) AS [Opened yesterday],
SUM(IIF([FkStatus] = 2 AND RequestedDate = DATE()-1, 1, 0)) AS [Close yesterday],
SUM(IIF([FkStatus] <> 2 AND RequestedDate = DATE(), 1, 0)) AS [Opened today],
SUM(IIF([FkStatus] = 4, 1, 0)) AS [Need More Information],
SUM(IIF([FkStatus] = 1, 1, 0)) AS [Pending ECN],
SUM(IIF([FkStatus] = 3, 1, 0)) AS [Pending-Parts Split]
FROM TbChangeRequest
GROUP BY TbChangeRequest.RequestedDate;

Thanks



Edited 3 time(s). Last edit at 06/23/2011 05:32PM by guidomarcel.
Re: Need help in formating
October 03, 2010 09:01PM
Hi TazQuebec,
thanks for your feedback.
Here is the best I can do by switching off the linebreaks for conditions:
SELECT   TbChangeRequest.RequestedDate,
         SUM(
         IIF([FkStatus]<>2 AND RequestedDate=DATE()-1,1,0)) AS [Opened yesterday],
         SUM(
         IIF([FkStatus]=2 AND RequestedDate=DATE()-1,1,0)) AS [Close yesterday],
         SUM(
         IIF([FkStatus]<>2 AND RequestedDate=DATE(),1,0)) AS [Opened today],
         SUM(
         IIF([FkStatus]=4,1,0)) AS [Need More Information],
         SUM(
         IIF([FkStatus]=1,1,0)) AS [Pending ECN],
         SUM(
         IIF([FkStatus]=3,1,0)) AS [Pending-Parts Split]
FROM     TbChangeRequest
GROUP BY TbChangeRequest.RequestedDate;
I still need to improve this, i.e. to avoid a linvtreak before "IIF" inside scalar functions. Do you agree?

Regards
Guido
Re: Need help in formating
October 04, 2010 02:25PM
Yes that be great.

Thanks

P.S. I like your utility.
Re: Need help in formating
December 27, 2010 12:59PM
Hi TazQuebec,
I will try to include this feature in the 2011 February Release
Regards
Guido
Re: [startedcool smiley] Need help in formating
June 22, 2011 09:44AM
Hi, with current formatting options and switching-off linebreaks before AND keyword, the following format can be achieved:
SELECT   TbChangeRequest.RequestedDate                                                     ,
         SUM( IIF([FkStatus]<>2 AND RequestedDate=DATE()-1,1,0)) AS [Opened yesterday]     ,
         SUM( IIF([FkStatus] =2 AND RequestedDate=DATE()-1,1,0)) AS [Close yesterday]      ,
         SUM( IIF([FkStatus]<>2 AND RequestedDate=DATE(),1,0))   AS [Opened today]         ,
         SUM( IIF([FkStatus] =4,1,0))                            AS [Need More Information],
         SUM( IIF([FkStatus] =1,1,0))                            AS [Pending ECN]          ,
         SUM( IIF([FkStatus] =3,1,0))                            AS [Pending-Parts Split]
FROM     TbChangeRequest
GROUP BY TbChangeRequest.RequestedDate;

Best Regards
Guido
Re: [solved thumbs up] Need help in formating
June 22, 2011 07:21PM
What is "current formatting"?

Here what I got now.

SELECT   TbChangeRequest.RequestedDate,
         SUM(
         IIF([FkStatus] <> 2 AND RequestedDate = DATE()-1, 1, 0)) AS [Opened yesterday],
         SUM(
         IIF([FkStatus] = 2 AND RequestedDate = DATE()-1, 1, 0)) AS [Close yesterday],
         SUM(
         IIF([FkStatus] <> 2 AND RequestedDate = DATE(), 1, 0)) AS [Opened today],
         SUM(
         IIF([FkStatus] = 4, 1, 0)) AS [Need More Information],
         SUM(
         IIF([FkStatus] = 1, 1, 0)) AS [Pending ECN],
         SUM(
         IIF([FkStatus] = 3, 1, 0)) AS [Pending-Parts Split]
FROM     TbChangeRequest
WHERE    TbChangeRequest.RequestedDate >= #2011-08 - 01# AND TbChangeRequest.RequestedDate <= #2011-08 - 31#
GROUP BY TbChangeRequest.RequestedDate;

The AND behave the same inside the IIF and in the WHERE

Here what I would like.
SELECT   TbChangeRequest.RequestedDate,
         SUM(IIF([FkStatus] <> 2 AND RequestedDate = DATE()-1, 1, 0)) AS [Opened yesterday]     ,
         SUM(IIF([FkStatus] =  2 AND RequestedDate = DATE()-1, 1, 0)) AS [Close yesterday]      ,
         SUM(IIF([FkStatus] <> 2 AND RequestedDate = DATE()  , 1, 0)) AS [Opened today]         ,
         SUM(IIF([FkStatus] =  4, 1, 0))                              AS [Need More Information],
         SUM(IIF([FkStatus] =  1, 1, 0))                              AS [Pending ECN]          ,
         SUM(IIF([FkStatus] =  3, 1, 0))                              AS [Pending-Parts Split]
FROM     TbChangeRequest
WHERE    TbChangeRequest.RequestedDate >= #2011-08-01#
AND      TbChangeRequest.RequestedDate <= #2011-08-31#
GROUP BY TbChangeRequest.RequestedDate;

Thanks all for your help
Re: [solved thumbs up] Need help in formating
June 23, 2011 05:28PM
Hi,
did you use the most recent release "June 2011"?
With "current formatting options" I meant the default options.
you are right, the AND in the WHERE conditions behave exactly in the same way as the AND in the IIF clause. To separate this, I would need to add options specifically for the IIF-statement. Will put this to TODO-list.

Best Regards
Guido
How to format the way I would like
June 10, 2011 11:35PM
When I format my SQL string with the June version here the result

SELECT
           IIF(TbTransit.FkCategory = 2,
                      IIF([COUNTRY_CODE] IN('CA'                     ,
                                            'US'                     ,
                                            'MX'), 5, 6), 7) AS Ligne,
           SUM(TbTransit.BO_Qty * TbTransit.[UnitPrice])     AS [Value]
FROM       TbTransit
INNER JOIN MD_SRC_LFA1
ON         TbTransit.Vendor = MD_SRC_LFA1.VENDOR_NUMBER
WHERE      TbTransit.PkTransit IN(SELECT    TbTransitDtl.FkTransit
           FROM       TbSemaine
           INNER JOIN TbTransitDtl
           ON         TbSemaine.PkSemaine = TbTransitDtl.FkSemaine
           WHERE      TbSemaine.Annee     = 2011
           AND        TbSemaine.Mois      = 5)
GROUP BY
           IIF(TbTransit.FkCategory = 2,
                      IIF([COUNTRY_CODE] IN('CA',
                                            'US',
                                            'MX'), 5, 6), 7)
ORDER BY
           IIF(TbTransit.FkCategory = 2,
                      IIF([COUNTRY_CODE] IN('CA',
                                            'US',
                                            'MX'), 5, 6), 7) ;


Here what I would like

SELECT     IIF(TbTransit.FkCategory = 2, IIF([COUNTRY_CODE] IN('CA', 'US', 'MX'), 5, 6), 7) AS Ligne,
           SUM(TbTransit.BO_Qty * TbTransit.[UnitPrice])     AS [Value]
FROM       TbTransit
INNER JOIN MD_SRC_LFA1
ON         TbTransit.Vendor = MD_SRC_LFA1.VENDOR_NUMBER
WHERE      TbTransit.PkTransit IN(SELECT    TbTransitDtl.FkTransit
           FROM       TbSemaine
           INNER JOIN TbTransitDtl
           ON         TbSemaine.PkSemaine = TbTransitDtl.FkSemaine
           WHERE      TbSemaine.Annee     = 2011
           AND        TbSemaine.Mois      = 5)
GROUP BY   IIF(TbTransit.FkCategory = 2, IIF([COUNTRY_CODE] IN('CA', 'US', 'MX'), 5, 6), 7)
ORDER BY   IIF(TbTransit.FkCategory = 2, IIF([COUNTRY_CODE] IN('CA', 'US', 'MX'), 5, 6), 7) ;


Can it be done or come close to that?

Thanks
Re: [solved thumbs up] Need help in formating
June 23, 2011 05:32PM
Hi TazQuebec,
I merged your 2 threads in one thread as they are about the same subject. Hope it is OK for you.
Regards
Guido
Author:

Your Email (Optional):


Subject:


Spam prevention:
Please, solve the mathematical question and enter the answer in the input field below. This is for blocking bots that try to post this form automatically.
Question: how much is 21 plus 25?
Message: