473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help with a stored procedure/query?

I did a join on two tables to get the following results. I saved the
results in a #temptable.
id table2id table2descrip dateinserted
================================================== ==
1 3 descrip1 11/3/2002
2 4 descrip2 11/2/2002
3 3 descrip1 11/4/2001
4 3 descrip1 10/5/2003
5 4 descrip2 12/8/2001
6 5 descrip3 9/10/2002

I want to query that #temptable to get the max date for each table2id
and only return those record. So I need a query to get the follow
results...

id table2id table2descrip dateinserted
================================================== ==
2 4 descrip2 11/2/2002
4 3 descrip1 10/5/2003
6 5 descrip3 9/10/2002

Question...
What query can I make with #temptable to give me the results?
Jul 20 '05 #1
1 1234
oj
try...

select *
from #tmp t1
where t1.id=(select top 1 id
from #tmp t2
where t2.table2id=t1.table2id
order by dateinserted desc)

--
-oj
RAC v2.2 & QALite!
http://www.rac4sql.net

<ne********@yahoo.com> wrote in message
news:70**************************@posting.google.c om...
I did a join on two tables to get the following results. I saved the
results in a #temptable.
id table2id table2descrip dateinserted
================================================== ==
1 3 descrip1 11/3/2002
2 4 descrip2 11/2/2002
3 3 descrip1 11/4/2001
4 3 descrip1 10/5/2003
5 4 descrip2 12/8/2001
6 5 descrip3 9/10/2002

I want to query that #temptable to get the max date for each table2id
and only return those record. So I need a query to get the follow
results...

id table2id table2descrip dateinserted
================================================== ==
2 4 descrip2 11/2/2002
4 3 descrip1 10/5/2003
6 5 descrip3 9/10/2002

Question...
What query can I make with #temptable to give me the results?

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: berthelot samuel | last post by:
Hi everyone, I am currently trying to write a report based on a View of SQL Server. Basically, I have 3 tables : Hardware, SoftwareInstalled and Software with SoftwareInstalled that keeps track of...
6
by: Praty77 | last post by:
Hi - I hope some one can help me with this. I am using sql server 2000 I have a stored procedure that is using cursors and a few joins, and writes to a few tables. (I can post the code if...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
10
by: Thomas R. Hummel | last post by:
I have a stored procedure that suddenly started performing horribly. The query plan didn't look right to me, so I copy/pasted the code and ran it (it's a single SELECT statement). That ran pretty...
1
by: Raquel | last post by:
Have a question on the Stored procedure method code generated by DB2 development center for Java stored procedures. Suppose I have a requirement to return the resultset consisting of FIRSTNME,...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
1
by: RSH | last post by:
Im trying to create a stored procedure of the following code. I want to set it so that I have to send the first 4 variables (@DB, @BackUpFile,@TestDB,@RestoreFile). I am having trouble when i try...
7
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
3
by: Darth Ferret | last post by:
This thing is about to drive me crazy. I have about 50 queries in the AS400 that I need to put on a menu. Once I conquer this I have a bunch more rpg reports that I need to pass a date to. In the...
17
by: Riaaaa | last post by:
Pls check my code for the stored procedure which i created for the companydetails including companyid P.K. Not Null int(4), companyname Not Null varchar (20), address varchar(30) where...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.