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 |
|
Vickyinrhyme
Starting Member
4 Posts |
Posted - 2009-07-29 : 15:13:36
|
| For some reason I need a query like thisSET QUOTED_IDENTIFIER OFFDeclare @ValStartDate DateTime,@ValEndDate DateTime,@SecIds Varchar(300)Set @ValStartDate = '2009-02-25'Set @ValEndDate = '2009-02-26'Set @SecIds = "'" + '637844309' + "'" + ',' + "'" + 'IJECE' + "'" + ',' + "'" + 'IJECF' + "'" + ',' + "'" + '887147114' + "'" + ',' + "'" + 'G7127P142' +"'" + ',' + "'" + '863346102' + "'" + ',' + "'" + '8318K4107' + "'" Select @SecIdsUse EYISP40Select DistinctSec.SecurityId As [Security ID],SecType.TypeName As [Security Type],PriceList.PriceSourceName As [Independent Pricing Source],Sec.IssuerDescription As [Pricing Source Description],PriceList.PriceDate As [Pricing Date],PriceList.price As [Unit Price],PriceList.ExchangeName As [Securities Exchange] From Security SecInner Join SecurityType SecType On Sec.TypeID = SecType.TypeIDLeft Join(Select t.PriceDate,PrSrce.PriceSourceName,PriceHist1.price,t.SecurityID,Exch.ExchangeNameFrom (Select SecurityId,PriceDate,Min(PriceHist.PriceSourceID) AS source From PriceHistory PriceHist Where PriceDate Between @ValStartDate and @ValEndDate GROUP BY PriceDate,SecurityID) t INNER JOIN PriceHistory PriceHist1 On t.PriceDate = PriceHist1.PriceDate AND t.source = PriceHist1.PriceSourceID And PriceHist1.SecurityID = t.SecurityId And PriceHist1.PriceDate Between @ValStartDate and @ValEndDate Inner Join PriceSource PrSrce On t.source = PrSrce.PriceSourceID Inner Join Exchange Exch On PriceHist1.ExchangeID = Exch.ExchangeID )PriceList On PriceList.SecurityID = Sec.SecurityIDWhere Sec.TypeID in(Select TypeID from dbo.SecurityType Where ClassID In(Select ClassID From dbo.SecurityClass Where ClassName In ('Equities - US')))And Sec.SecurityID In (@SecIds)And PriceList.PriceSourceName is Not NullBut the @SecIds variable is not replacing its value correctly (the query result shows no record but infact there is record).Please help me |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-07-29 : 15:41:55
|
I think you need to use dynamic SQL for this...something like below.DECLARE @strIDs VARCHAR(300) SET @strIDs = '''637844309''' + ',' + '''IJECE''' SELECT @strIDs DECLARE @SQL VARCHAR(1000) SELECT @SQL = 'SELECT * FROM Security ' SELECT @SQL = @SQL + 'WHERE SecurityID in (' + @strIDs + ')' EXEC( @SQL) |
 |
|
|
Vickyinrhyme
Starting Member
4 Posts |
Posted - 2009-07-29 : 15:46:29
|
| will try this and let know. thanks for the idea |
 |
|
|
|
|
|
|
|