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

  • Home
  • SEARCH
  • 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 7617083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:03:30+00:00 2026-05-31T03:03:30+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

tbl_TransactionDishout

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

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

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,
  t1.field14,
  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 (t1.field14 <> 'Test Card'   and t1.field14 is null) 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),
  t1.field14
ORDER BY
  convert(varchar, CAST(ISNULL(t1.created,t2.created) AS DATETIME), 111) DESC

Now, here I am facing one problem that the fourth column is executing something wrong because I have One record in tbl_TransactionDishout table yesterday which has responsecode = 0000 and also is not a ‘Test card’ but still I am getting 0 count.

relation between tbl_transaction and tblCustomer is having same cardno…

  • 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-31T03:03:31+00:00Added an answer on May 31, 2026 at 3:03 am

    Based on what you have said in the comments section, I think you need to change one snippet of code…

    • What I want is that card should not have field14 as 'Test card'

    (t1.field14 <> 'Test Card' and t1.field14 is null)
    

    =>

    (t1.field14 <> 'Test Card'  OR  t1.field14 is null)
    

    Build up a logic table to check if you really want AND or if you want OR

    field14     | (field14 <> 'Test Card') | (t1.field14 is null) | A OR B | A AND B
    --------------------------------------------------------------------------------
    'Test Card' |            FALSE         |        FALSE         | FALSE  | FALSE
    NULL        |            NULL          |        TRUE          | TRUE   | FALSE
    'Any Card'  |            TRUE          |        FALSE         | TRUE   | FALSE
    

    EDIT Follow up to comment

    Using OR in the code above can’t yield TRUE when Field14 is 'Test Card'. Both tests yield FALSE and so the result must be FALSE.

    You need to break things down in stages. Debugging should be done by testing pieces at a time and graddually proving what work to isolate what doesn’t. Never try to sort everything out at once, approach things methodically.

    Run this test…

    SELECT
      *,
      CASE WHEN field14 <> 'Test Card'                     THEN 1 ELSE 0 END     Test1,
      CASE WHEN field14 IS NULL                            THEN 1 ELSE 0 END     Test2,
      CASE WHEN field14 <> 'Test Card' OR  field14 IS NULL THEN 1 ELSE 0 END     1_OR_2,
      CASE WHEN field14 <> 'Test Card' AND field14 IS NULL THEN 1 ELSE 0 END     1_AND_2
    FROM
      tblCustomer
    
    • 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.