Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 suugest a query to get the data from 2 tables depe

Author  Topic 

anilr499
Starting Member

18 Posts

Posted - 2012-06-25 : 03:23:26
Hi,

i have two tables named

PRJCOMMENT and PRJSCHEDULE ...

Now i need to get the latest date from

table name---- column name

PRJCOMMENT---- date_upload
PRJSCHEDULE ---- prc_date_updated


based on prj_id...

in the above two tables they have different prj_id's

i mean they dont have common prj_id...

now i need to get the latest date from them depending on

prj_id....

how can i relate both in one query an get the latest date...

i need to check for prj_id in both tables...

how can i proceeedd...

than you...

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-06-25 : 04:30:00
Not clear what yoou want but maybe

select prj_id, max(date_upload), max(prc_date_updated)
from
(
select prj_id, date_upload, prc_date_updated = converrt(datetime,null)
from PRJCOMMENT
union all
select prj_id, null, prc_date_updated
from PRJSCHEDULE
) a
group by prj_id



==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

sakthiananth
Starting Member

2 Posts

Posted - 2012-06-25 : 05:47:38
Thank you dude.. it's useful to me and also i've one doubt that why we're using "NULL" here

Let's keep learning to explore towards future.):
Go to Top of Page

anilr499
Starting Member

18 Posts

Posted - 2012-06-25 : 06:22:26
hi nigelrivett,

thank you for your support ...

i used your query as shown below


select prj_id, max(date_upload) , max(prc_date_updated)
from
(
select prj_id, date_upload, prc_date_updated = convert(datetime,null)
from PRJCOMMENT
union all
select prj_id, null, prc_date_updated
from PRJSCHEDULE
) a WHERE prj_id='PRJ0000704'
group by prj_id

my output is

PRJ0000704 28/02/2012 NULL

i need first two columns

i mean we need to check in two tables ...
but should display date in only one column...
because we dont get two dates at a time...
for example..
if PRJCOMMENT contains the required date
then PRJSCHEDULE does not contains any thing and vice versa...
because i need to display the output date in a single column in my report.....
thank you....
Go to Top of Page
   

- Advertisement -