| Author |
Topic |
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2010-02-24 : 07:26:02
|
| i am doing select @startingtime=convert(VARCHAR(20),@mydate,102) + ' '+ convert(VARCHAR(20),starttime,108) from parkingtimes where site=@site order by starttimeI thought in this case the @startingtime would be = to the first entry shows ordered by starttime but it seems to not be doing how do i get the smallest starttime? |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-02-24 : 07:41:28
|
quote: Originally posted by esthera i am doing select @startingtime=convert(VARCHAR(20),@mydate,102) + ' '+ convert(VARCHAR(20),starttime,108) from parkingtimes where site=@site order by starttimeI thought in this case the @startingtime would be = to the first entry shows ordered by starttime but it seems to not be doing how do i get the smallest starttime?
If you want to sort on first output column then Try using "Order by 1" |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2010-02-24 : 07:49:48
|
| but i want the first one order by starttime - but only the first collumn returned |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-24 : 07:50:47
|
| select @startingtime=convert(VARCHAR(20),@mydate,102) + ' '+ convert(VARCHAR(20),min(starttime),108) from parkingtimes where site=@siteMadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-24 : 09:53:03
|
quote: Originally posted by esthera i am doing select @startingtime=convert(VARCHAR(20),@mydate,102) + ' '+ convert(VARCHAR(20),starttime,108) from parkingtimes where site=@site order by starttimeI thought in this case the @startingtime would be = to the first entry shows ordered by starttime but it seems to not be doing how do i get the smallest starttime?
if you've multiple records satisfying this condition you'll get only a single value stored in your variable. if you specifically want first value use top 1------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2010-02-24 : 10:04:50
|
| what's the correct syntax for top 1 in this case? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-24 : 10:08:31
|
| [code]select top 1 @startingtime=convert(VARCHAR(20),@mydate,102) + ' '+ convert(VARCHAR(20),starttime,108) from parkingtimes where site=@site order by starttime[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-25 : 01:39:03
|
quote: Originally posted by esthera what's the correct syntax for top 1 in this case?
Why didn't you use my solution?MadhivananFailing to plan is Planning to fail |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2010-02-25 : 01:46:29
|
| Why didn't you use my solution?sorry i missed that - i did top now - is that better to use then top? is any better? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-02-25 : 02:57:04
|
quote: Originally posted by esthera Why didn't you use my solution?sorry i missed that - i did top now - is that better to use then top? is any better?
If you use top you need order by too where in min you dont needMadhivananFailing to plan is Planning to fail |
 |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2010-02-25 : 03:05:37
|
| thanks:) |
 |
|
|
|