[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

rest assure about the date

rodchar

3/23/2007 1:40:00 PM

hey all,
i have this query that goes a little some like this?
select @testDate = dbDate
from Table1
where employeeID = 1
order by dbDate DESC
PRINT @testDate

Results:
1,2/17/07
1,7/18/06
1,1/17/06

Can i rest assure that @testDate is always going to be the last date in the
resultset?

thanks,
rodchar
2 Answers

Raymond D'Anjou

3/23/2007 2:43:00 PM

0

I'm tempted to say 'yes' but I wouldn't write code like this.
To make it clearer for anyone else looking at your statement.
I would prefer:

SET dbDate = (select MAX(@testDate) from Table1 where employeeID = 1)

SET is the prefered method for assigning values to variables.

"rodchar" <rodchar@discussions.microsoft.com> wrote in message
news:271C01E4-0274-48AF-BD62-014D33727611@microsoft.com...
> hey all,
> i have this query that goes a little some like this?
> select @testDate = dbDate
> from Table1
> where employeeID = 1
> order by dbDate DESC
> PRINT @testDate
>
> Results:
> 1,2/17/07
> 1,7/18/06
> 1,1/17/06
>
> Can i rest assure that @testDate is always going to be the last date in
> the
> resultset?
>
> thanks,
> rodchar


rodchar

3/24/2007 4:16:00 AM

0

Thank you for the feedback.
Rod.

"Raymond D'Anjou" wrote:

> I'm tempted to say 'yes' but I wouldn't write code like this.
> To make it clearer for anyone else looking at your statement.
> I would prefer:
>
> SET dbDate = (select MAX(@testDate) from Table1 where employeeID = 1)
>
> SET is the prefered method for assigning values to variables.
>
> "rodchar" <rodchar@discussions.microsoft.com> wrote in message
> news:271C01E4-0274-48AF-BD62-014D33727611@microsoft.com...
> > hey all,
> > i have this query that goes a little some like this?
> > select @testDate = dbDate
> > from Table1
> > where employeeID = 1
> > order by dbDate DESC
> > PRINT @testDate
> >
> > Results:
> > 1,2/17/07
> > 1,7/18/06
> > 1,1/17/06
> >
> > Can i rest assure that @testDate is always going to be the last date in
> > the
> > resultset?
> >
> > thanks,
> > rodchar
>
>
>