开发者

Access dynamic amount of SQL Views

I believe this is a toughie!

I have 2 databases. Destiny and Source

In Destiny I have a table, which contains a list of names of views.

Such as:

GasPriceSourceID    Name
1   ICIS Heren TTF Bid
2   ICIS Heren TTF Offer
3   ICIS Heren TTF Midspread
4   NPG Spot
8   AEQ SYS Sell
9   AEQ SYS Buy
10  ICIS Heren Gaspool Midspread

So first I will call the View: ICIS Heren TTF Bid on the database: Source Then ICIS Heren TTF Offer and so on.

This will be done in a C# console application.

Normally I would use a ADO.NET Entitiy Data Model. But this creates a static model of the database - but views will be 开发者_如何学Goadded and removed daily.

All the views return 3 things: ID, Date, and Value.

I need to move these prices to a table in the database: Destiny

So in short. Destiny has a list of price sources. Each source has a lot of prices, which will be put into a table on Destiny.


Since you don't provide enough details just some general pointers:

  • Build the SQL strings "manually" in the app
    NOT recommended and prone to problems (Security, Performance...)

  • Build a stored procedure which in turn builds and execute the SQL SELECT and returns a CURSOR
    Can be a bit more secure (esp. can avoid SQL injection) since the Stored Procedure would check for the existence of the View first...

BTW: what exactly are you doing when you access those Views ?

EDIT - after more information from OP:

I suspect your model is a bit off... what you describe would VERY EASILY be solved by having EXCATLY ONE View with the columns Source, ID, Date, and Value.

This would make all the dynamic SQL and the resulting problems just go puff... because then you could just use "normal queries" with a WHERE Source = 'ICIS Heren TTF Bid' for example... any other technology like EF and/or LINQ etc. would be available and working "out of the box"...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜