Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
vikasmahajan

sql query joins

Dear all

Find attachment of  two screens  scr1 & scr2  

In following  query I want to fatch all records of last day of the month which is available in my second table

Table 1

SELECT  DivTarDate,

    DivAnnualTgt,

    DivMonthlyTgt,

    "SG_ID"

FROM "QLIKVIEW_SIM_DB".dbo.DivTarget

where divtardate <=  30/06/2013   { from table2 }

Table 2

                 o/p   :  30/06/2013

   SELECT MIN([INVDET_DOCDATE]) AS MinDate,

              -- MAX([INVDET_DOCDATE]) AS MaxDate

              -- DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,MAX([INVDET_DOCDATE]))+1,0)) AS MaxDate  /* Logic Build to take last day of month for correction of growth % */

                 CASE WHEN getdate()=DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,MAX([INVDET_DOCDATE]))+1,0)) THEN

                 DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,MAX([INVDET_DOCDATE]))+1,0))

                ELSE MAX([INVDET_DOCDATE]) END  AS MaxDate

FROM QLIKVIEW_SIM_DB.[dbo].FACT_QV_SalesInvoice_Transaction

How to achive the same.

Thanks in advance

Vikas

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.
If you want to go quickly, go alone. If you want to go far, go together.
1 Solution

Accepted Solutions
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Try this script.

Max_Min:

SELECT MIN([INVDET_DOCDATE]) AS MinDate,

              -- MAX([INVDET_DOCDATE]) AS MaxDate

              -- DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,MAX([INVDET_DOCDATE]))+1,0)) AS MaxDate  /* Logic Build to take last day of month for correction of growth % */

                 CASE WHEN getdate()=DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,MAX([INVDET_DOCDATE]))+1,0)) THEN

                 DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,MAX([INVDET_DOCDATE]))+1,0))

                ELSE MAX([INVDET_DOCDATE]) END  AS MaxDate

FROM QLIKVIEW_SIM_DB.[dbo].FACT_QV_SalesInvoice_Transaction

Let vMax = timestamp(peek('MaxDate',0,'Max_Min'),'DD-MMM-YYYY hh:mm:ss');

Table1:

SELECT  DivTarDate,

    DivAnnualTgt,

    DivMonthlyTgt,

    "SG_ID"

FROM "QLIKVIEW_SIM_DB".dbo.DivTarget

where divtardate <= $(vMax);

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!

View solution in original post

3 Replies
sujeetsingh
Master III
Master III

Vikas i am not seeing any attachments .

plz post a sample !!!

vikasmahajan
Author

Hii,

Thanks.. I have attached screen short this doubt in sql only  how  to pick date from table 2 with where condition.

Vikas

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution & like it.
If you want to go quickly, go alone. If you want to go far, go together.
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Try this script.

Max_Min:

SELECT MIN([INVDET_DOCDATE]) AS MinDate,

              -- MAX([INVDET_DOCDATE]) AS MaxDate

              -- DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,MAX([INVDET_DOCDATE]))+1,0)) AS MaxDate  /* Logic Build to take last day of month for correction of growth % */

                 CASE WHEN getdate()=DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,MAX([INVDET_DOCDATE]))+1,0)) THEN

                 DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,MAX([INVDET_DOCDATE]))+1,0))

                ELSE MAX([INVDET_DOCDATE]) END  AS MaxDate

FROM QLIKVIEW_SIM_DB.[dbo].FACT_QV_SalesInvoice_Transaction

Let vMax = timestamp(peek('MaxDate',0,'Max_Min'),'DD-MMM-YYYY hh:mm:ss');

Table1:

SELECT  DivTarDate,

    DivAnnualTgt,

    DivMonthlyTgt,

    "SG_ID"

FROM "QLIKVIEW_SIM_DB".dbo.DivTarget

where divtardate <= $(vMax);

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!