bit of a Friday moment with some SQL



Hia all

 

I am having a bit of a Friday moment with some SQL and am hoping someone can show me the light…??

I am sure its very basic – but the finer details are some what eluding me today…

 

I have this script equivalent…

 

            Select

                        B.Description

                        Count(B.Description)

                        Sum(A.Amount)

            From

                        Table1 A

                        Join Table2 B on (A.id = B.id)

 

Where table A has one to many records of table B.

 

This runs fine, but what I am seeing is an incorrect Sum amount due to this one to many association between the two tables.

i.e. if an ID from Table A has £5 in the Amount column, and the same ID exists on 4 records on Table B – my sum result is coming back at £20, I only want a distinct £5.

 

My initial thought was to do something like putting Distinct in front of the A.Amount (Sum(Distinct A.Amount)) within the aggregate, but this groups by the money values, and not the ID…

 

I hope that makes sense to someone out there?!

Many thanks in advance!!

 

Christopher Hill

Swyddog Dadansoddi a Chymorth SQL

SQL Support Analyst

Canolfan Mileniwm Cymru

Wales Millennium Centre

 

Ebost\Email Christopher.Hill@wmc.org.uk

Ffon\Tel 029 2063 6372

 

www.wmc.org.uk

 

Dy Le Di

Make it Yours this year

 

Cysylltwch yn Gymraeg neu'n Saesneg fel dymunwch

Contact us in English or Welsh as you prefer

 

Plas Bute\Bute Place

Bae Caerdydd\Cardiff Bay

CF10 5AL

P Meddyliwch am yr amgylchedd cyn printio / Please consider the environment before printing this email

 



Mae’r ohebiaeth hon at ddefnydd y derbynnydd/derbynyddion bwriadedig yn unig. Os nad chi yw’r derbynnydd/derbynyddion bwriadedig, nodwch fod dosbarthu, copïo neu ddefnyddio’r ohebiaeth hon neu’r wybodaeth ynddi mewn unrhyw ffordd wedi ei wahardd yn gyfangwbl a gall fod yn anghyfreithlon. Os ydych wedi derbyn yr ohebiaeth hon trwy gamgymeriad a fyddech cystal â’i ddychwelyd i’r anfonwr. Yn yr achos hwn byddem yn ddiolchgar pe gallech hefyd anfon yr ohebiaeth at administrator@wmc.org.uk ac yna dileu’r e-bost a dinistrio unrhyw gopïau ohono. Cwmni cyfyngedig dan warrant, cofrestrwyd yng Nghymru a Lloegr. Rhif Cwmni 3221924. Rhif Elusen 1060458. Swyddfa gofrestredig: Plas Bute, Bae Caerdydd, Caerdydd CF10 3AL

This communication is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s) please note that any form of distribution, copying or use of this communication or the information in it is strictly prohibited and may be unlawful.If you have received this communication in error please return it to the sender. In this event would be grateful if you would also copy the communication to administrator@wmc.org.uk then delete the email and destroy any copies of it. A company limited by guarantee, registered in England and Wales. Company number 3221924. Charity number 1060458. Registered office: Bute Place, Cardiff Bay, Cardiff CF10 5AL



[edited by: Todd Lantry at 1:44 PM (GMT -6) on 20 Jul 2009] added subject to post TL
  • Former Member
    Former Member $organization in reply to Former Member

    PERFECT SOLUTION!  Thanks Dale!

     

    I love these Tessisutra forums!

     

    Penny

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Dale Aucoin
    Sent: Tuesday, February 22, 2011 10:16 AM
    To: Tabor, Penny
    Subject: Re: [Tessitura Technical Forum] <No Subject>

     

    Penny,

    I don't think this is kept in a table, It is calculated based on the end_dt which is stored in tx_const_cust.  For easier use you can also see only active constituencies in the view vxs_const_cust.

    Dale

    From: Penny Tabor <bounce-pennytabor2237@tessituranetwork.com>
    Sent: 2/22/2011 8:59:58 AM

    Does anyone know what table contains the “Inactive” field that displays on the Constituencies screen?  It is not located in the tx_const_cust table as I expected.  We have constituencies for our staff levels, and when staff changes from one level to another, they end up with multiple constituency entries, so  I need to be able to report on the constituencies that are not inactive. 

     

     

    Penny Tabor

    IT Manager

    Midland Center for the Arts

    Midland, MI 48640

                                Error! Filename not specified.

     

     




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!

  • Based on this where clause:

     

    SELECT a.*

    FROM dbo.TX_CONST_CUST a

          JOIN dbo.VRS_CONSTITUENCY b ON a.constituency = b.id

    WHERE (getdate() >= (Coalesce(a.start_dt,'1900-01-01')) and getdate() <= (Coalesce(a.end_dt,'2999-12-31'))) or

          (getdate() >= (Coalesce(a.start_dt,'1900-01-01')) and (Coalesce(a.start_dt,'1900-01-1')) > (Coalesce(a.end_dt,'2999-12-31')))

     

     

    A row is active if the current date falls between the start and end dates OR the end date falls before the start date and the start date is earlier than the current date.

    -Ryan

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Dale Aucoin
    Sent: Tuesday, February 22, 2011 10:16 AM
    To: Ryan Creps
    Subject: Re: [Tessitura Technical Forum] <No Subject>

     

    Penny,

    I don't think this is kept in a table, It is calculated based on the end_dt which is stored in tx_const_cust.  For easier use you can also see only active constituencies in the view vxs_const_cust.

    Dale

    From: Penny Tabor <bounce-pennytabor2237@tessituranetwork.com>
    Sent: 2/22/2011 8:59:58 AM

    Does anyone know what table contains the “Inactive” field that displays on the Constituencies screen?  It is not located in the tx_const_cust table as I expected.  We have constituencies for our staff levels, and when staff changes from one level to another, they end up with multiple constituency entries, so  I need to be able to report on the constituencies that are not inactive. 

     

     

    Penny Tabor

    IT Manager

    Midland Center for the Arts

    Midland, MI 48640

                                

     

     




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!

  • Former Member
    Former Member $organization in reply to Former Member

    Thanks everyone for the tips!  I appreciate the fast responses.

     

    Penny

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Ryan Creps
    Sent: Tuesday, February 22, 2011 10:26 AM
    To: Tabor, Penny
    Subject: RE: [Tessitura Technical Forum] <No Subject>

     

    Based on this where clause:

     

    SELECT a.*

    FROM dbo.TX_CONST_CUST a

          JOIN dbo.VRS_CONSTITUENCY b ON a.constituency = b.id

    WHERE (getdate() >= (Coalesce(a.start_dt,'1900-01-01')) and getdate() <= (Coalesce(a.end_dt,'2999-12-31'))) or

          (getdate() >= (Coalesce(a.start_dt,'1900-01-01')) and (Coalesce(a.start_dt,'1900-01-1')) > (Coalesce(a.end_dt,'2999-12-31')))

     

     

    A row is active if the current date falls between the start and end dates OR the end date falls before the start date and the start date is earlier than the current date.

    -Ryan

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Dale Aucoin
    Sent: Tuesday, February 22, 2011 10:16 AM
    To: Ryan Creps
    Subject: Re: [Tessitura Technical Forum] <No Subject>

     

    Penny,

    I don't think this is kept in a table, It is calculated based on the end_dt which is stored in tx_const_cust.  For easier use you can also see only active constituencies in the view vxs_const_cust.

    Dale

    From: Penny Tabor <bounce-pennytabor2237@tessituranetwork.com>
    Sent: 2/22/2011 8:59:58 AM

    Does anyone know what table contains the “Inactive” field that displays on the Constituencies screen?  It is not located in the tx_const_cust table as I expected.  We have constituencies for our staff levels, and when staff changes from one level to another, they end up with multiple constituency entries, so  I need to be able to report on the constituencies that are not inactive. 

     

     

    Penny Tabor

    IT Manager

    Midland Center for the Arts

    Midland, MI 48640

                                

     

     




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!

  • Former Member
    Former Member $organization in reply to Jan LaRocque

    Does anyone know what item in security controls the ability to view/close other user’s batches?  We have a ticket office assistant that cannot see all users batches, but other ticket office people can and we cannot tell where the difference is in security/permissions.

     

    Thanks in advance,

     

     

    Penny Tabor

    IT Manager

    Midland Center for the Arts

    Midland, MI 48640

                                acerp

     

     

     

  • Hi Penny,

    It's the Manager in Security, so if someone's userid is a Manager of a Group they can close any users batch who is part of that group.


    Caryl

     

  • Former Member
    Former Member $organization in reply to Former Member

    Great – thanks so much!

     

    Penny

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Caryl Jones
    Sent: Friday, October 14, 2011 9:42 AM
    To: Tabor, Penny
    Subject: Re: [Tessitura Technical Forum] <No Subject>

     

    Hi Penny,

    It's the Manager in Security, so if someone's userid is a Manager of a Group they can close any users batch who is part of that group.


    Caryl

     

    From: Penny Tabor <bounce-pennytabor2237@tessituranetwork.com>
    Sent: 10/14/2011 8:31:35 AM

    Does anyone know what item in security controls the ability to view/close other user’s batches?  We have a ticket office assistant that cannot see all users batches, but other ticket office people can and we cannot tell where the difference is in security/permissions.

     

    Thanks in advance,

     

     

    Penny Tabor

    IT Manager

    Midland Center for the Arts

    Midland, MI 48640

                                Error! Filename not specified.

     

     

     




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!