Extend existing tsql query to get all customers, even if they have no instances of the previous query - thought this would be easy, but...

Hi all,
The previous query is absolutely ok.
The only thing i want to change is ...
get all the previous available ve1 AND NEW: if a AGNR has no ve1-instance, regardless get an ve1-instance with the agnr filled but f.e. the other fields empty
The grouping could made in reporting-logic later, and not in the tsql-query.
resultset i need:
- all agnr, if the have an ve1-instance or not
Groups (hierarchy) i need, later in Report:
- AGNR
   - ve1 (with all the left joind fields pg, vnfk, vnpk, vm (if they are)
   - if a agnr has no instance of ve1 --> print: "NO ver available"
SELECT
ve1.new_verid,
ve1.new_no,
ve1.statuscode,
ve1.statuscodename,
ve1.createdon,
ve1.createdby,
ve1.createdbyname,
ve1.new_begin,
DATEPART(yyyy, ve1.new_begin) AS begin_year,
ve1.new_end,
ve1.new_vn_fid,
ve1.new_vn_fidname,
ve1.new_vn_kid,
ve1.new_vn_kidname,
vnpk.new_how_old,
ve1.new_vg,
ve1.new_vgname,
ve1.new_vs,
ve1.new_vsname,
ve1.new_vstat,
ve1.new_vstatname,
ve1.new_zw,
ve1.new_zwname,
ve1.new_bn_zw,
ve1.new_rlz_v,
ve1.new_pgid,
ve1.new_pgidname,
pg.accountnumber as pg_accountno,
ve1.new_agnr_agnr_avmid,
ve1.new_agnr_agnr_avmidname,
AGNR.new_vm_kid AS vm_contactid,
AGNR.new_vm_kidname AS vm_contactidname,
ve1.new_efv,
ve1.new_efvname,
CASE
WHEN ve1.new_vn_kid IS NOT NULL THEN 'Private Customer'
WHEN ve1.new_vn_fid IS NOT NULL THEN 'Account Customer'
ELSE 'Kunde'
END AS kunde_typ,
DATEPART(yyyy, vnpk.birthdate) as vnpk_birth_year,
CASE
WHEN ((ve1.new_rlz_v IS NOT NULL) OR (ve1.new_rlz_v > 0))
THEN ve1.new_rlz_v
WHEN (DATEPART(yyyy, ve1.new_begin) IS NOT NULL) AND (DATEPART(yyyy, vnpk.birthdate) IS NOT NULL)
THEN 65 - ((DATEPART(yyyy, ve1.new_begin)) - (DATEPART(yyyy, vnpk.birthdate)))
ELSE 20
END AS vlz_calc,
CASE
WHEN ((ve1.new_bnj IS NOT NULL) OR (ve1.new_bnj > 0)) THEN ve1.new_bnj
WHEN ((ve1.new_bn_zw IS NOT NULL) OR (ve1.new_bn_zw > 0))
THEN
CASE
WHEN new_zw = '100000008' THEN ve1.new_bn_zw * 12
WHEN new_zw = '100000004' THEN ve1.new_bn_zw * 4
WHEN new_zw = '100000002' THEN ve1.new_bn_zw * 2
WHEN new_zw = '100000001' THEN ve1.new_bn_zw * 1
WHEN new_zw = '100000006' THEN ve1.new_bn_zw
ELSE 0
END
ELSE 0
END AS bnj_calc
FROM
Filterednew_ver AS ve1
LEFT OUTER JOIN Filterednew_agnr AS AGNR
ON ve1.new_agnr_agnr_avmid = AGNR.new_agnrid
LEFT OUTER JOIN FilteredAccount AS pg
ON ve1.new_pgid = pg.accountid
LEFT OUTER JOIN FilteredAccount AS vnfk
ON ve1.new_vn_fid = vnfk.accountid
LEFT OUTER JOIN FilteredContact AS vnpk
ON ve1.new_vn_kid = vnpk.contactid
LEFT OUTER JOIN FilteredContact AS vm
ON AGNR.new_vm_kid = vm.contactid
WHERE
(ve1.createdon >= @Begin_Week)
AND (ve1.createdon <= @End_Week)
AND (ve1.new_vg = @vg)
AND (ve1.statuscode = '1')
AND (ve1.new_efv <> '100000000' OR ve1.new_efv IS NULL)
AND (ve1.new_vstat <> '100000004' OR ve1.new_vstat IS NULL)
AND (ve1.new_zw IN ('100000008','100000004','100000002','100000001','100000006'))
ORDER BY
ve1.createdon
i thought, and tried with right joins, but i think i need to change the sight (the complete query)?
thx for all kind of help
Greets Peb

Hi Peb,
Please provide sample data and expected results.

Similar Messages

  • HT4623 in our house we have 2 iphones but only since the upgrade to ios 5 my partner also gets all texts my firends who have iphones too.. how do i stop this?

    in our house we have 2 iphones but only since the upgrade to ios 5 my partner also gets all texts my firends who have iphones too.. how do i stop this from happening? I do not get messages he is sent though??
    Please can you help and let me know what I need to do to fix this - thanks!

    you guys are using the same apple id in imessage seperate apple id and you wont have the problem

  • Trying to download just ONE audiobook... it downloaded them all!  even though I have "selected" and just the one checked -- help!

    i downloaded the iTunes update to 11.1.   Normally I just download one audio boo to my iPhone (5) at one time, this time, even though I had "selected audiobooks" checked and just the one audio book checked, it downloaded all of them.   That's taking up almost a gig of space on my 16G phone.   Before I realized it was trying to download every book, i deleted about 500 pictures (okay, I really needed to delete them anyway...) along with a bunch of apps I never use, to make room for what I thought was just the one new book I purchased....  is there a fix for this?

    Hi!
    This could be done in many ways so it's quite hard to pin point what's going on and how it's done.
    The first thing I would do is to reset the the router you have, creating a new password for loging on in case they have gained access this way, then create a new password for the wireless network if you are using it.
    Then reinstall your computer, if they/you have installed some software and gotten a Trojan, the only way to get rid of it to 100% is to reinstall. There is no meaning in trying to find it and uninstalling it since it's gotten this far allready.
    Depending on what router you have, you might be able to get the logs and see from where they are connecting and trying to pinpoint their location.
    There are probably other ways to find out more, but if this happened to me, the first thing I would do is to get rid of the problem, ignoring who they are.
    Best regars
    Andreas Molin
    Andreas Molin | Site: www.guidestomicrosoft.com | Twitter: andreas_molin

  • Hi i was wondering wether i can retrieve (get back) any photos when they have been deleted (by the way it wernt backed up)

    This is my first ever comment

    If you don't have a backup or never imported your pics to your computer, then no you can't retrieve it.

  • Query to get all ports assigned and used by EBS instance.

    Hi,
    Can some one pleaase help to get
    Query to get all ports assigned and used by EBS instance.
    Help is appreaciated.
    Regards,
    Milan

    MILAN RATHOD wrote:
    Hi,
    Can some one pleaase help to get
    Query to get all ports assigned and used by EBS instance.
    Help is appreaciated.
    Regards,
    MilanIn addition to the thread referenced above by Helios, please check the context files and (Oracle E-Business Suite R12 Configuration in a DMZ [ID 380490.1] -- F. List of Ports to Open in a DMZ Configuration).
    Thanks,
    Hussein

  • I formatted my ext hard drive and changed it to mac os x extended(journaled). then i put in all my data back. after a while, i insert the hard drive but my macbook cannot read it. plz help

    i formatted my ext hard drive and changed it to mac os x extended(journaled). then i put in all my data back. after a while, i insert the hard drive but my macbook cannot read it. plz help

    SanandaDutta 
    tried on a different mac. The same problem exists.
    If that is the case, its extremely unlikely you have a bad USB cable on the seagate, rather as I mentioned earlier a bad SATA bridge card.
    If the Seagate 1TB USB external wont open on either Mac and youve verified same (try a diff. USB cable if you have one however this is nearly never the case),....then to get the data off that HD (unless it is dead which is also extremely unlikely),......then you would need to extract the HD from its case and insert same into either a HD dock or USB HD enclosure.
    8 out of 10  seemingly dead inopperable 1-3+ year old external HD are perfectly fine, rather the cheap 50 cent SATA bridge card fries and dies (alas)
    reply back if you need help in extracting same. 

  • TS3988 My wife bought an iPad Air and synced contact from our PC (Outlook), now all our contacts in Outlook have gone and we have to go to iCloud to get them, and even then they are a bit jumbled. How do I get my data back onto my PC?

    My wife bought an iPad Air and synced contact from our PC (Outlook), now all our contacts in Outlook have gone and we have to go to iCloud to get them, and even then they are a bit jumbled. How do I get my data back onto my PC?

    If you can see the iCloud contacts in Outlook, you can copy them back to your PC by selecting all the contacts (click one, then press Control-A), then drag and drop the selected contacts to Contacts under My Contacts on the left sidebar of Outlook.
    If you want to copy your calendar back to Outlook, select your iCloud calendar on the left sidebar of Outlook, switch to the list view (select View from the ribbon, then click Change View>List), select your events (click on a single event, then press Control-A), then control drag and drop them to Calendar under My Calendars on the left sidebar.
    Then you can sign out of iCloud on the iCloud control panel and your local copies will still be there.  If you want to add your iCloud email account back to iCloud, you can do this with these settings: http://support.apple.com/kb/HT4864.

  • HT201269 hi i need help, i just go a new iPhone 5 and i want to put all my backed up stuff on, but it doesn't show on the list, how do i get all my stuff back and yes i did backup the old phone

    hi i need help, i just go a new iPhone 5 and i want to put all my backed up stuff on, but it doesn't show on the list, how do i get all my stuff back and yes i did backup the old phone

    Follow the explicit instructions in the article from which the thread was started and restore the device from the backup of the previous device.

  • Can you still get a iCloud even tho you have already use all of the free times?

    I need to know how to get a iCloud even tho you have use all of your free turns

    Maybe this previous discussion.
    https://discussions.apple.com/message/19867885#19867885

  • How do I get music already on my laptop on (amazon, Emodio, Windows media player) into my itunes library, I have just done the icloud match as I thought this would do it for me, but the only songs on my phone are the 40 that I already had in itunes..

    How do I get music already on my laptop into my itunes account library? I have just done the icloud match thinking this would pick them all up, but it hasn't, all it has done is match the 40 songs I already have in my itunes library. I wanted to get some more  music onto my iphone and I am stuck. If someone could assist, that would be great. Thanks. Sue

    Suzybabe wrote:
    Fantastic, how easy this was, searched and searched through itunes help and forums earlier today and this little gem of instruction is nowhere to be found.
    Many thanks ed2345.
    Sue
    Sue,
    Glad to hear that it was helpful.  Enjoy the music!
    Ed

  • IPad can't get past step 8 when syncing. I have to unplug before the end. Is this normal? What do I do to solve the issue?

    iPad can't get past step 8 when syncing. I have to unplug before the end. Is this normal? What do I do to solve the issue? Thanks. JD

    It is syncing through everything and then failing to close out. If I disconnect then the libraries are all there although I have lost a movie and a few tracks downloaded as a result of this.
    JD

  • I transferred itunes library from old PC to new PC. The content all shows when I launch iTunes on the new PC now. The previous content does not show in iTunes but folder still looks like it is on hard drive on new PC. Suggestions on how to properly merge?

    I transferred itunes library from old PC to new PC. The content all shows when I launch iTunes on the new PC now. The previous content does not show in iTunes but folder still looks like it is on hard drive on new PC. Suggestions on how to properly merge?

    Before you connect any device to a new library go to the Devices tab of the the preferences panel via Edit > Preferences (Windows) or iTunes > Preferences (Mac) and ensure the box next to Prevent iPods, iPhones, and iPads from syncing automatically is ticked. You can now safely connect the device to your computer without the danger of media being automatically deleted or overwritten.
    To get all your content off your connect your iPad to your new computer.
    Then use a 3rd party piece of software to transfer your content
    I have found Senuti useful but there are others listed in the article I linked to in a previous post.
    https://discussions.apple.com/docs/DOC-3991
    That will let you transfer your non purchased content
    For Purchased content log in to iTunes on the new computer
    In Itunes Store click on Purchased under the Quick Links section on the right.
    Download any music by clicking on the cloud button

  • ITunes re-syncs all photos even if they haven't changed

    I've found that when syncing my iPhone or iPad, some times, iTunes decides to resync all the photos on the device (i.e. wipe and the sync again).
    I've not changed any of the photos so am not sure what's triggering this.
    My configuration is set up to simply sync all photos from one of my folders (iPod Photos)
    The strange thing is that this issue seems to occure randomly - i.e. doesn't happen every time I sycn.
    Anyone have any ideas why this would be happening? 
    thanks

    I don't have a solution, but I can take a guess at what's going on.
    My photos are on a shared folder in the Cloud (Mozy Sync).  There are two laptops in the family that access this folder on a regular basis (husband and wife).  Each laptop has iTunes installed.  Wife syncs her iPhone to her laptop using her instance of iTunes.  Husband syncs his iPhone to his laptop using his instance of iTunes.
    Whether the pictures are re-synced depends on who synced last.  For example, if Wife synced last, and Husband syncs, all the pictures are reloaded from scratch.  Now, if Husband syncs again, only the changed pictures are loaded.  But if Wife syncs next, all of the pictures are reloaded from scratch.
    My theory is that the two instances of iTunes are fighting over the thumbnails in the folder iPod Photo Cache. Thumbnails are scaled-down versions of the picture files that take up less storage space, but are suitable for display on the iPhone's screen.  If Wife was the last person to sync, Husband's iTunes doesn't recognize the thumbnails, so it proceeds to erase them and rebuild them.  However, if Husband performs the next sync, his iTunes recognizes the thumbnails and syncs only items that changed.
    If this is the problem, then the question is:  How do I get both instances of iTunes to share the same thumbnails without re-creating them each time?  Alternately, can I  have two instances of the iPod Photo Cache, one for Wife and one for Husband?
    Is this resonating with anyone?

  • TS1292 I received 3 $10 gift card that I ahve not used yet the codes say they have been redeemed. The cards were a gift less thn 1 year ago. All 3 cards start xxmp. What might the concern be?

    A year ago Xmas I got 3 $10 gift cards, starting code on all 3 is xxmp, and even though I have not used them the computer says they have been used.

    Hello SBentley22,
    I can only imagine how upset I would be to discover that over $1000 in gift card funds seemed to be missing. I certain that I would not do well with the additional complications that you've described either. I apologize for you and your boyfriend having to cope with this situation. Certainly this was never our goal.
    I was unable to locate the purchases or returns that you mention using the information you provided when you signed up for Best Buy Unboxed. I would very much like to look into this situation for you and do what I can to help, but I will need more information to begin. If you will please send me a private message that includes your full name, telephone number, and the Customer Service PIN from the receipt where the gift card was issued, I'll get started with my research.
    Please know that I'm extremely grateful that you took the time to bring your situation to our attention. I look forward to hearing from you.
    Sincerely,
    John|Social Media Specialist | Best Buy® Corporate
     Private Message

  • Having a problem with dates when I send my numbers doc to excel. dates are all out and that they have to cut and paste individual entries onto their spreadsheet. Any idea how I can prevent this

    having a problem with dates when I send my numbers doc to excel. dates are all out and that they have to cut and paste individual entries onto their spreadsheet. Any idea how I can prevent this.
    I'm using Lion on an MBP and Numbers is the latest version

    May you give more details about what is wrong with your dates ?
    M…oSoft products aren't allowed on my machines but I use LibreOffice which is a clone of Office.
    When I export from Numbers to Excel and open the result with LibreOffice, the dates are correctly treated.
    To be precise, dates after 01/01/1904 are correctly treated. dates before 01/01/1904 are exported as strings but, as it's flagged during the export process, it's not surprising.
    Yvan KOENIG (VALLAURIS, France) mardi 3 janvier 2012
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
    My iDisk is : http://public.me.com/koenigyvan
    Please : Search for questions similar to your own before submitting them to the community
    For iWork's applications dedicated to iOS, go to :
    https://discussions.apple.com/community/app_store/iwork_for_ios

Maybe you are looking for

  • Can validation check can be set for vendor master record .

    Hi Experts , User wants to remove two existing payment methods,instead of removing i think to set validation for the vendor master record . can validation can be set for vendor master record ? PLease suggest me with advice. Thanks Pardha

  • File name already exists?

    The past few days, I've had trouble exporting certain sequences from FCPHD using Compressor 2. Basically, when I go to export via compressor, the error "File Name Already Exists" pops up. However, the sequence still appears in the compressor window.

  • How can I call a server function by a button?

    Hello, world... I have a problem... I need to call a server function by pushing a button. I put the condition on the label... This is my script: writeBtn1.addEventListener (MouseEvent.CLICK,writeFile1); private function writeFile1 (e:MouseEvent=null)

  • How to get rid of multiple instance of same machine

    Hi, I have an issue with my MacPro as I have multiple instance of the same computer. Let me explain : My machine appears as MacPro. but sometime it connect as MacPro (2), or MacPro (3) and so on... I now have MacPro (11). This happens when I get prob

  • Installing AIR app issues

    Hey, I've installed AIR no problem according to the installer. I'm running Windows 7 Home Premium. I tried to install an application and the AIR installer never comes up. I tested AIR on my other PC running XP and it worked just fine. Any suggestions