Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7633373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:51:58+00:00 2026-05-31T06:51:58+00:00

Table Structures: tblCustomer Customer_id created field1 field2 cardno field14 ———————————————————————————————— 1014 2010-05-25 12:51:59.547 Cell

  • 0

Table Structures:
tblCustomer

Customer_id  created                 field1            field2        cardno       field14
------------------------------------------------------------------------------------------------    
1014         2010-05-25 12:51:59.547 Cell Phone        abc@lmn.com   1234567890   Test Card
1015         2010-08-15 12:51:59.547 Email             abc@xyz.com   2345678891   NULL

tbl_TransactionDishout

Trnx_id   offerNo   TerminalID      Created                  VirtualCard
-------------------------------------------------------------------
1         1014      170924690436418 2010-05-25 12:51:59.547  1234567890

Relation between tbl_transaction and tblCustomer is having same cardno.
Is it possible to get the result as below date-wise records:

               Enrolled   Enrolled as Email  Enrolled as Text Deals Redeemed   
<First Date>   7          5                  2                6
<Next Date>    9          3                  6               14

Date should be from both tables even if it has zero records..

Enrolled          - Total No of records that is summation of Enrolled as Email and Enrolled as Text.      
Enrolled as Email - Where field1 = 'Email' from tblCustomer table
Enrolled as Text  - Where field1 = 'cell phone' from tblCustomer table
Deals Redeemed    - Where field14 <> 'Test Card' from tblCustomer table and    
                    where DishoutResponsecode = '0000' from tbl_Transaction table

My Existing Query:

SELECT
convert(varchar, CAST(ISNULL(t1.created,t2.created) AS DATETIME), 111) created,
COUNT(CASE WHEN (t1.field1 = 'E-mail' or t1.field1 = 'Cell Phone')  and (t1.field14 <>  'Test Card'  or t1.field14 is null) THEN 1 END) Enrolled,
COUNT(CASE WHEN t1.field1 = 'E-mail'            and (t1.field14 <> 'Test Card'   and t1.field14 is null) THEN 1 END) Enrolled_as_Email,
COUNT(CASE WHEN t1.field1 = 'Cell Phone'        and (t1.field14 <> 'Test Card'   and t1.field14 is null) THEN 1 END) Enrolled_as_Cell,
COUNT(CASE WHEN t2.DishoutResponseCode = '0000' and (IsNull(t1.field14, '') <> 'Test Card') THEN 1 END) Deals_Redeemed  
FROM  tblCustomer AS t1
FULL OUTER JOIN
      tbl_TransactionDishout t2
ON  t1.cardno = t2.VirtualCard and t1.created = t2.created
GROUP BY
      convert(varchar, CAST(ISNULL(t1.created,t2.created) AS DATETIME),      111)
ORDER BY
      convert(varchar, CAST(ISNULL(t1.created,t2.created) AS DATETIME), 111) DESC          

Last 4-5 records in tblCustomer table

created                 cardno               field14
----------------------------------------------------------
2012-03-07 10:03:00.034 1234007600101240    
2012-03-05 04:02:00.040 1234007600602122    
2012-03-01 06:25:50.400 1234010400972168     Test Card
2012-03-01 30:05:30.022 555566669999         Test Card
2012-03-01 50:50:20.450 666677778888         Test Card    

Last 4-5 records in tbl_TransactionDisout table

created                 VirtualCard         DishoutResponseCode
-----------------------------------------------------------------------
2012-03-09 13:18:02.703 1234010400972168    0010
2012-03-09 13:17:35.307 1234010400972168    0002
2012-03-09 13:17:14.237 1234010400972168    0007
2012-03-09 13:16:57.650 1234010400972168    0002
2012-03-08 21:13:57.137 1234010400475686    0000
2012-03-08 16:50:38.273 1234010400972168    0002
2012-03-08 16:50:26.070 1234010400972168    0007
2012-03-08 16:49:49.793 1234010400972168    0002    

So there is only one card in this with having response code ‘0000’ and also not a ‘Test Card’..But I am getting all the card with code = ‘0000’ and also having ‘Test Card’ so that means field14 is not able to compare because it is from the different table and different date..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:51:59+00:00Added an answer on May 31, 2026 at 6:51 am

    This is the result I get back with this query when I use the data that you specified in the main question:

    SELECT  
      convert(varchar, CAST(ISNULL(t1.created,t2.created) AS DATETIME), 111) created,  
      COUNT(CASE WHEN (t1.field1 = 'Email' or t1.field1 = 'Cell Phone')  and (t1.field14 <> 'Test Card'  or t1.field14 is null) THEN 1 END) Enrolled,
      COUNT(CASE WHEN t1.field1 = 'Email'            and (IsNull(t1.field14, '') <> 'Test Card') THEN 1 END) Enrolled_as_Email,  
      COUNT(CASE WHEN t1.field1 = 'Cell Phone'        and (IsNull(t1.field14, '') <> 'Test Card') THEN 1 END) Enrolled_as_Cell,  
      COUNT(CASE WHEN t2.DishoutResponseCode = '0000' and (IsNull(t1.field14, '') <> 'Test Card') THEN 1 END) Deals_Redeemed  
    FROM  
      tblCustomer AS t1  
    FULL OUTER JOIN  
      tbl_TransactionDishout t2  
        ON  t1.cardno = t2.VirtualCard  
        AND t1.created = t2.created  
    GROUP BY  
      convert(varchar, CAST(ISNULL(t1.created,t2.created) AS DATETIME), 111)  
    ORDER BY  
      convert(varchar, CAST(ISNULL(t1.created,t2.created) AS DATETIME), 111) DESC  
    

    Result:

    created                        Enrolled    Enrolled_as_Email Enrolled_as_Cell Deals_Redeemed
    ------------------------------ ----------- ----------------- ---------------- --------------
    2012/03/09                     0           0                 0                0
    2012/03/08                     0           0                 0                1
    2012/03/07                     1           0                 1                0
    2012/03/05                     1           0                 1                0
    2012/03/01                     0           0                 0                0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Table Structures: tblCustomer Customer_id created field1 field2 cardno field14 ------------------------------------------------------------------------------------------------ 1014 2010-05-25 12:51:59.547 Cell
Table Structures: tblCustomer Customer_id created field1 field2 cardno field14 ------------------------------------------------------------------------------------------------ 1014 2010-05-25 12:51:59.547 Cell
Table Structures: tblCustomer Customer_id created field1 field2 cardno -------------------------------------------------------- 1014 Test1 Cell Phone 123146
I have the following table structures. Table A id name 1 name1 2 name2
I found the following table structures while I was watching ruby on rails tutorial.
Say I have a database called Poll and have these two table structures. poll
I'm trying to bind a table of structures to a DataGridView. Loading and viewing
I have two tables with the following (simplified) structures: table "Factors" which holds data
I have a table TreeStructures wich holds structures of Trees. This table has columns
I have quite a few situations where I have database structures similar to: TABLE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.