Need SQL Query

  • Where FieldId and FieldValues are repeating, i need to query sum of field values based on the dates.

    EX - select sum(Fieldvalue) from EntityItemDetails where fieldid=21 and ((FieldValue<='12/20/2011' ANd FieldId=19) and ((FieldValue>='12/20/2011' ANd FieldId=19)))

  • Hi,

    I'm not sure exactly what you are asking but I think you are refering to a 'GROUP BY', check out BOL and see if that's what you are after.

    If not then can you clarify in a bit more detail what you are trying to acheive please?

  • You will need to start from here:

    http://qa.sqlservercentral.com/articles/Best+Practices/61537/

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Hi,

    Yes, I think you should be able to do this using a GROUP BY, if you are not familiar with that then there are loads of good examples on the internet, and BOL (Books OnLine) will document it as well.

    It's pretty much like saying, I have 3 columns (Country, Town and number of people). You would say the following;

    SELECT Country,

    Town,

    SUM(NumberOfPeople)

    FROM TableA

    GROUP BY Country,

    Town

    You are just saying, sum the people, by Country and Town.

    You just need to change this to work with your table and columns.

    If after you've read about it you still need some help then let me know.

    Nic

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply