Views - SELECT from VIEW and SELECT from the query inside view definition returning different results

Hi,
I am facing this weird issue. Any help would be appriciated.
I have view with the following definition:
CREATE VIEW [marketing].[OpenedMails]
AS
SELECT
ID_EmailAddress, 
ID_Date_Opened, 
ID_Contact, 
ID_MailSendJobs,
COUNT(ID_OpenedMails) AS OpenCount,
CASE
WHEN ROW_NUMBER() OVER (PARTITION BY CAST(ID_EmailAddress AS VARCHAR(10)) + ' ' + CAST(ID_MailSendJobs AS VARCHAR(10)) ORDER BY ID_Date_Opened) = 1 THEN 1 
ELSE 0 
END
AS UniqueOpenCount
FROM            
dbo.Fact_OpenedMails
where ID_Contact = 382340
GROUP BY ID_EmailAddress, ID_Date_Opened, ID_Contact, ID_MailSendJobs;
order by ID_MailSendJobs 
When I run the the select statement in the view definition I get combination of both 1 and 0 for the 'UniqueOpenCount' column.
But when I run the select from the view itself using the following query:
SELECT [ID_EmailAddress]
      ,[ID_Date_Opened]
      ,[ID_Contact]
      ,[ID_MailSendJobs]
      ,[OpenCount]
      ,[UniqueOpenCount]
  FROM [marketing].[OpenedMails]
I get equal amount of rows but only 0 values for the 'UniqueOpenCount' column which seems to be very weird to me. Why is this happening ? Can anyone help regarding how to solve this ??
Result from the select inside view definition:
Result from the select query directly from the view:
Thanks in advance.
Vivek Kamath

Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. You failed. Temporal
data should use ISO-8601 formats – you failed again. Code should be in Standard SQL AS much AS possible and not local dialect. 
This is minimal polite behavior on SQL forums. 
Things like “ID_Date_Opened” are wrong. The affixes “id” and “date” are called attribute properties in ISO-11179 and data modeling. Since a date is a unit of measurement on a temporal scale, it cannot be an identifier by definition. My guess is this would be
“open_date” if it were done right. And the only display format in ANSI/ISO Standard SQL is ISO-8601 (yyyy-mm-dd)
An email address of -1?? Email addresses are VARCHAR(256), not numeric. There is no reason to cast them AS string!
Your vague “mail_send_jobs” is plural, but columns hold scalars and cannot be plural by definition. The partition cause can hold a list of columns: 
WHEN ROW_NUMBER() 
     OVER (PARTITION BY email_address, mail_send_job 
               ORDER BY open_date)
     = 1 
THEN 1 ELSE 0 END 
This still makes no sense, but the syntax is better. You do not understand how ROW_NUMBER() works. 
Would you like to try again with proper Netiquette? 
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • Creating select option to get wadat from likp to use in the query

    Hi People,
    Urgent Help. I have to make a select-option in my selection screen for date to use the field wadat from likp. Now the after the following code what should I be doing:
    Selection-Screen BEGIN OF BLOCK b with frame Title t1.
    PARAMETERS:
    SELECT-OPTIONS: p_date for likp-wadat.
    SELECTION-SCREEN END OF BLOCK b.
    INITIALIZATION.
    AT SELECTION-SCREEN.
    START-OF-SELECTION.
    <b>SELECT avbeln alfdat awadat akunnr bwerks bspart INTO
    CORRESPONDING FIELDS OF TABLE typ_tab FROM likp as a INNER JOIN lips as b on avbeln = bvbeln where wadat IN p_dat.</b>
    On the selection screen there will be two boxes for the from -to date...How does it work? If I have to make it only for one date or for range of dates. Please help asap. I have to use this value in a report to pull out delivery document details from likp and lips through the query mentioned above.
    Thanks in advance.
    AM

    Hey Nishanth,
    Thanks for the reply. I made the changes as suggested but when I am entering a date which does not exist in the table, the screen does nothing. Can you suggest something for that.
    Here is my code:
    tables: likp.
    SELECTION-SCREEN BEGIN OF BLOCK b_0 WITH FRAME TITLE date.
    SELECT-OPTIONS p_date FOR likp-wadat NO-EXTENSION.
    PARAMETERS p_glAccNo(80) TYPE C.
    SELECTION-SCREEN END OF BLOCK b_0.
    DATA: BEGIN OF typ_likp occurs 0,
                     vbeln LIKE likp-vbeln, " Bill Of Lading Number
                     lfdat LIKE likp-lfdat,
                     wadat LIKE likp-wadat,
          END OF typ_likp.
    AT SELECTION-SCREEN ON p_date.
    if p_date[] is NOT INITIAL.
    SELECT vbeln wadat INTO TABLE typ_likp FROM LIKP WHERE wadat IN p_date.
    IF sy-subrc <> 0.
    WRITE: / 'No Values for this date.'.
    Exit.
    ENDIF.
    ELSE.
    WRITE: 'NO ENTRIES HAVE BEEN MADE'.
    ENDIF.
    START-OF-SELECTION.
    SELECT vbeln lfdat wadat INTO TABLE typ_likp fROM LIKP where
    wadat in p_date.
    LOOP AT typ_likp.
    Write: / typ_likp-vbeln, typ_likp-lfdat, typ_likp-wadat,
           / 'I am here.'.
    ENDLOOP.
    Please reply soon. I need to finish this at the earliest.
    Thanks for your help, regards,
    AM

  • Select statement returns different results from 9i and 10g

    Hi all,
    Would appreciate if someone could help to solve this puzzle here:
    I have the exact the statements running on Oracle 9i and 10g, why do they return different results?
    Select unique(GroupDesc) , GroupSeq from Module where ModuleId in (Select ModuleId from User_Access where UserId='admin') and Status='A'
    In Oracle 9i:
    Both columns returned as follows...
    GroupDesc | GroupSeq
    In Oracle 10g:
    Only one column returned, the column with unique keyword was missing...
    GroupSeq
    Could anyone enlighten me?

    yes, the table structure... actually the CREATE TABLE statement...
    with some sample data (INSERT INTO)
    and the actual queries (both of them - copy-paste them from each separate environment)
    you can use tags around the statements this will format it to a fixed font - making it easier to read
    Edited by: Alex Nuijten on Feb 20, 2009 10:05 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • New iPad 2 16mb; how do I sync (download) selectively - pictures from iPhoto and music from iTunes?  Or do I have to download all? I only have 16 mb on my iPad 2.?

    My new iPad 2 has only 16 mb. I have hundreds of pix on my MacBook Pro laptop  iPhoto and I don't know how many mbs of music on my iTunes. I haven't sycned my new iPad with my MacBook Pro yet because I fear I will overrun the available space I have on the iPad. Is there any way to selectively download pix and iTunes to the iPad?

    You should have 16 GIG on yourr iPad, not 16 meg
    When you hook them up to iTunes select to 'manually manage music and videos' and that will allow you to choose what bits and pieces you can put on your device.

  • Whenever I reply to an e-mail the window comes up but without the paper airplane in the top left corner.  The only way to send the reply is to close it and save as a draft.  Then I can pull it up from Drafts and it has the airplane on it.

    Whenever I reply to an e-mail the window comes up but without the paper airplane in the top left corner.  The only way to send the reply is to close it and save as a draft.  Then I can pull it up from Drafts and it has the airplane on it.

    Launch Mail.
    Click "New Message" in the Toolbar.
    When the new message window opens up, click "View" menu in the menu bar.
    Select "Show Toolbar" from the dropdown.
    or
    Select "Customize Toolbar from the dropdown.
    When the Customize Toolbar sheet drops down, drag  "Send" button
    or  drag "default set" into the toolbar.
    Click "Done".

  • Problem in Retrieve Image from DB and display in the JSP page

    Hi All,
    I did one JSP Program for retriveing image from DB and display in the JSP Page. But when i run this i m getting "String Value" output. Here i have given my Program and the output. Please any one help to this issue.
    Database Used : MS Access
    DSN Name : image
    Table Name: image
    Image Format: bmp
    Output : 1973956
    Sample Program:_
    <%@ page contentType="text/html;charset=windows-1252"%>
    <%@ page import="java.io.*" %>
    <%
         try{
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection conn = DriverManager.getConnection("jdbc:odbc:image");
              Statement st = conn.createStatement();
              ResultSet rs = st.executeQuery("SELECT images FROM image");
              String imgLen="";
              if(rs.next()){
                   imgLen = rs.getString(1);
                   out.println(imgLen.length());
              if(rs.next()){
                   int len = imgLen.length();
                   byte [] rb = new byte[len];
                   InputStream readImg = rs.getBinaryStream(1);
                   int index=readImg.read(rb, 0, len);
                   System.out.println("index"+index);
                   st.close();
                   response.reset();
                   response.setContentType("image/jpg");
                   response.getOutputStream().write(rb,0,len);
                   response.getOutputStream().flush();
         }catch(Exception ee){
              out.println(ee);
    %>
    Thanks,
    Senthilkumar S

    vishruta wrote:
    <%
    %>Using scriptlets is asking for trouble. Java code belongs in Java classes. Use a Servlet.
                   out.println(imgLen.length());Your JSP was supposed to write an image to the output and you wrote some irrelevant strings to the output before? This will corrupt the image. It's like opening the image in a text editor and adding some characters before to it.
                   byte [] rb = new byte[len];Memory hogging. Don't do that.
              out.println(ee);You should be throwing exceptions and at least printing its trace, not sending its toString() to the output.
    You may find this article useful to get an idea how this kind of stuff ought to work: [http://balusc.blogspot.com/2007/04/imageservlet.html].

  • I just downloaded an album from itunes and 2 of the tracks will not play at all, they cut off. I need help with this??

    I just downloaded an album from itunes and 2 of the tracks will not play at all, they cut off. I need help with this??

    Does the track play correctly in Quicktime Player?  If it does then it is an iTunes issue.  If it doesn't then it is possible the file was not completely downloaded, or is corrupt.
    Downloading (using iOS or computer) past purchases from the App Store, iBookstore, and iTunes Store - http://support.apple.com/kb/ht2519 - enabled with iTunes 10.3 and newer; not available in all countries; apps, books (not audiobooks), music, t.v. shows, and movies (some - not all studios have permitted this). Movies currently available in the USA only. Downloading previously purchased movies and TV shows requires iTunes 10.6 or later.  Discontinued items not available. For items not included in the iCloud list (e.g., ringtones), or locations or computer systems where iCloud is not (yet?) available, you only get one download per fee paid. 
    If it can be downloaded again, delete the track from iTunes.
    Select the store on the left side of iTunes.
    Click on Purchased on the right side under Quick Links.
    You can re-download your available previous purchases.
    If it is corrupt and you cannot download it a second time, contact Apple.  Contact iTunes Store support staff through the report a problem links in your account history or,
    iTunes Customer Service Contact - http://www.apple.com/support/itunes/contact.html > Get iTunes support via Express Lane > iTunes > iTunes Store

  • I accidently put the same keyword in all pictures. How to back off from that and just having the right pictures marked?

    I accidently put the same keyword in all pictures. How to back off from that and just having the right pictures marked?

    Once more after some thinking: I have a Lightroom backup from jan 5th. It seems better to use this, but how do I do to force LR to start from the latest backup?
    11 jan 2015 kl. 18:11 skrev NicHamilton <[email protected]>:
    I accidently put the same keyword in all pictures. How to back off from that and just having the right pictures marked?
    created by NicHamilton <https://forums.adobe.com/people/NicHamilton> in Photoshop Lightroom - View the full discussion <https://forums.adobe.com/message/7085634#7085634>
    I'm not a Mac user so can't speak specifically about using Time Machine but if it is possible to get to an earlier version of the Lightroom Catalog then I would try that, yes.  Backups are another way of doing this.  Just make sure you make a copy of your current Catalog before replacing it with another one.
    If the reply above answers your question, please take a moment to mark this answer as correct by visiting: https://forums.adobe.com/message/7085634#7085634 and clicking ‘Correct’ below the answer
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page:
    Please note that the Adobe Forums do not accept email attachments. If you want to embed an image in your message please visit the thread in the forum and click the camera icon: https://forums.adobe.com/message/7085634#7085634
    To unsubscribe from this thread, please visit the message page at , click "Following" at the top right, & "Stop Following"
    Start a new discussion in Photoshop Lightroom by email <mailto:[email protected]> or at Adobe Community <https://forums.adobe.com/choose-container.jspa?contentType=1&containerType=14&container=33 16>
    For more information about maintaining your forum email notifications please go to https://forums.adobe.com/thread/1516624 <https://forums.adobe.com/thread/1516624>.
    Lars Magnusson
    Business Evolution
    +46 70 245 28 90

  • I have an iphone4. every time i turn it on i get an old I.D. and a message saying, "Apple password " then my email address  and asks for the password. I have a different account that itunes on my computer recognizes.  How do i remove this from my phone?

    i have an iphone4. every time i turn it on i get an old I.D. and a message saying, "Apple password " then my email address  and asks for the password. I have a different account that itunes on my computer recognizes.  How do i remove this from my phone?

    to remove that account.
    go to settings > iTunes & App Stores > click on that apple ID then sign out.

  • I made an iMovie, 6.0.3 using music from iTunes and photos from the Internet. It looked fine on iMovie, but when I uploaded it to youtube,some of the photo near the beginning was corrupted.What steps should I take to export iMovie for youtube?

    I made an iMovie, 6.0.3 using music from iTunes and photos from the Internet. It looked fine on iMovie, but when I uploaded it to youtube, some of the photo near the beginning were corrupted on youtube. I tried a different photo, and the corruption took place at the same moment of the video. How do I prepare the video for export to get it ready for youtube? I wasn't sure whether to clik web or web streaming. Am I supposed to clik Quick Time after I clik Share?

    I unfortunately cannot remember where I got the 'trrndlines' plugin... I assume that it must have been from CFX (as it is located under /Users/Dom/Library/iMovie/Plug-ins/cfx/XXXtrrndlines.bundle).
    As for what it does, I also do not know, as I do not think I ever used it in my previous video projects.
    At this stage, I think I just need to uninstall it so that iMovie doesnt try to use it.
    Do you know how to uninstall a CFX plugin in iMovie?
    NOTE: I have re-installed iMovie 6.0.4 (instead of iMovie 6.0.3), but still encounter the same issue.

  • HT4859 I just got a replacement phone and want to do a restore from Icloud and cant find the back up there.

    I just got a replacement phone and want to do a restore from Icloud and cant find the back up there.
    I purchased extra space and have backed up my ipad and my iphone.  I backed up my iphone this am and again around 3.00pm when I was in the apple store.  I came home to restore the phone and now cant see the back up on icloud.  where did it go and how can I see all of my storage on icloud

    Welcome to the Apple Community.
    settings > general > reset > erase all content and settings, once complete the set up assistant will ask if you have an iCloud back up, follow on screen instruction to restore from it.

  • Copying and pasting adjustments.  When I copy the adjustments of an image, I thought I could then select several images and batch paste the adjustments to all selected images. But instead it's only pasting to the first photo of the selection. What am I do

    Copying and pasting adjustments.  When I copy the adjustments of an image, I thought I could then select several images and batch paste the adjustments to all selected images. But instead it's only pasting to the first photo of the selected. What am I doing wrong?

    Copy and Paste develop settings in Develop mode on multiple photos on the film strip works for me, even with Auto-Sync turned off.  Lr5.6 OSx 10.8.5

  • HT201210 I try to restore my iPad from iTunes and I receive the error 3014.

    I try to restore my iPad from iTunes and I receive the error 3014. Any idea how to resolve this issue ?
    I am running Windows 7.

    iPad: Basic troubleshooting
    http://support.apple.com/kb/TS3274
    iOS: Resolving update and restore alert messages
    http://support.apple.com/kb/TS1275
    iPad: Unable to update or restore
    http://support.apple.com/kb/ht4097
     Cheers, Tom
    Error 3014 may indicate that you need to free up more disk space on the computer before trying to restore again.
    Message was edited by: Texas Mac Man

  • I somehow changed a video in my imovie to zero fps, so it just plays black.  The video still exists on my desktop but even when I delete the files from imovie and reimport them the file is still in zero fps and play black.

    somehow changed a video in my imovie to zero fps, so it just plays black.  The video still exists on my desktop but even when I delete the files from imovie and reimport them the file is still in zero fps and play black.

    I'm not sure of your question.
    Are you asking how to use Photoshop?
    Or are you asking for the dimensions of video iMovie uses?
    It edits in 720P HD, which is 1280x720.
    You can make it a bit bigger so you can zoom in.
    Much bigger then this is a waste of time.

  • Get the data  from excel and insert into the database

    I want to read the data from excel file, get the data from excel and insert into the database.

    You can use the Apache POI HSSF API to read data from Excel files and you can use the Sun JDBC API to insert data in database.
    This has nothing to do with JSP/JSTL.

Maybe you are looking for

  • Saving Downloads to a different partition

    Hi, Just joined your forum, Hi All. Can anyone help with this one. I'm getting very low on space in my C partition. I split my hard drive when installing XP and would like to get iTunes to save downloads into G: my large partition. I uninstalled iTun

  • Possible to run iMovie 6 HD and iMovie 5?

    Is there a way to have both versions of iMovie on my mac? I've tried installing the older version of iMovie from the 2 OS disks that came with the computer that also contain bundled software, and when I try to do a custom installation and choose only

  • Album track not playing in iTunes11, plays through iTunes Match on other devices

    I bought an album (Raymond van het Groenewoud - Live in de AB) but track 3 (Jouw Liefde) refuses to play in iTunes 11. It plays fine on my iPhone4 and iPad3 through iTunes Match...

  • How do I set up PayPal Standard?

    I have been through the tutorial and the help files, but, I keep getting an 'invalid vendor account'. I only want to use Standard, but originally set up PayPal PayFlow, which is in the settings. Not sure what to do to clear out PayFlow and just use S

  • Workbook in webtemplate

    hello friends, can u please tell me that can we create a web tamplate for workbook..? i have created a workbook and saved 2 queries in that. now i want to execute the same workbook on qweb so i will be able to view both view on web.. please tell me h