Re: Please help me with this query...thanks
From: Dandy WEYN (no_spam_info_at_dandyman.net)
Date: 02/22/04
- Next message: martino rivaplata: "Truncating, Deleting or Shrinking Log File"
- Previous message: Dandy WEYN: "Re: Please help me with this query...thanks"
- In reply to: Kim: "Please help me with this query...thanks"
- Next in thread: Kim: "Re: Please help me with this query...thanks"
- Reply: Kim: "Re: Please help me with this query...thanks"
- Reply: Otis B. Driftwood: "Re: Please help me with this query...thanks"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 22 Feb 2004 21:10:38 +0100
You need to pivot the table
http://www.dandyman.net/sql/samplesByTopic.aspx?topicid=2&id=6
-- Dandy Weyn, Belgium MCSE, MCSA, MCDBA, MCT http://www.dandyman.net Check my SQL Server resource pages (currently under construction) http://www.dandyman.net/sql "Kim" <kim@diz.se> wrote in message news:uEsYs2X#DHA.3568@TK2MSFTNGP10.phx.gbl... > How can I do this in one query > > I've got a table like this > > ID RESOURCEID DATE QUANTITY > > The Id is unique (but just a counter not of interest here), there may be one > resourceid for each date and then an asscoiated quantity. > I want to select all resourceid (distinct) and I just want just the > resourceid and the date and quantity associated with that post that is less > than today but nearast in time. > > To examplify > > if some records look like like this > > ID RESOURCEID DATE QUANTITY > 1 1 2003-12-01 1.3 > 2 1 2004-01-25 1.4 > 3 2 2002-01-01 1.7 > 4 2 2003-07-27 2.8 > > I want my select statement to return only the two following post > > ID RESOURCEID DATE QUANTITY > 2 1 2004-01-25 1.4 > 4 2 2003-07-27 2.8 > > That is one post for each resource and the post should be the one were the > date is less than today > > I want to do this without using stored procedures or view, since I'm not > allowed to create this kind if objects in the database. > I thought that perhaps using a #temp table would be a solution but I just > can't get it to work as I want > > Thanks in advance > > >
- Next message: martino rivaplata: "Truncating, Deleting or Shrinking Log File"
- Previous message: Dandy WEYN: "Re: Please help me with this query...thanks"
- In reply to: Kim: "Please help me with this query...thanks"
- Next in thread: Kim: "Re: Please help me with this query...thanks"
- Reply: Kim: "Re: Please help me with this query...thanks"
- Reply: Otis B. Driftwood: "Re: Please help me with this query...thanks"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|