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.
| Author |
Topic |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2007-12-06 : 05:19:40
|
| Hi,This query returns the correct results without the group byI now would like to have max(Bid_Price), min(Ask_Price) and then use the group by Import_DateHow do I add the max and min to the first two fields in the select query please?select Bid_Price = case when dbo.isreallynumeric(ltrim(rtrim(Bid_Price))) = 1 then convert(decimal(12, 4), ltrim(rtrim(Bid_Price))) end, Ask_Price = case when dbo.isreallynumeric(ltrim(rtrim(Ask_Price))) = 1 then convert(decimal(12, 4), ltrim(rtrim(Ask_Price))) end, Import_Date from tblPriceswhere source_id in (select source_id from tblSources where Security_ID = 125) and Import_Date >=dateadd(day, -7, dateadd(day,datediff(day,0,getdate()),0))group by Import_Date |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2007-12-06 : 05:31:32
|
| [code]select Max(Bid_Price) as Bid_Price, Min(Ask_Price) as Ask_Price, Import_Datefrom(select Bid_Price = case when dbo.isreallynumeric(ltrim(rtrim(Bid_Price))) = 1 then convert(decimal(12, 4), ltrim(rtrim(Bid_Price))) end, Ask_Price = case when dbo.isreallynumeric(ltrim(rtrim(Ask_Price))) = 1 then convert(decimal(12, 4), ltrim(rtrim(Ask_Price))) end, Import_Date from tblPriceswhere source_id in (select source_id from tblSources where Security_ID = 125)and Import_Date >=dateadd(day, -7, dateadd(day,datediff(day,0,getdate()),0))) agroup by Import_Date[/code] |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2007-12-06 : 05:35:00
|
| Is this a better method than using a table variable first and then select from the table variable? |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2007-12-06 : 05:44:58
|
| Generally, yes as you do not have the overhead of a table variable with the above. |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2007-12-06 : 06:03:31
|
| great, thanks |
 |
|
|
|
|
|
|
|