Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
"Dynamic" view question
"Dynamic" view question
Rate Topic
Display Mode
Topic Options
Author
Message
Mindy Hreczuck
Mindy Hreczuck
Posted Monday, September 24, 2012 12:59 PM
SSC Journeyman
Group: General Forum Members
Last Login: Monday, May 06, 2013 8:42 AM
Points: 79,
Visits: 478
We have a existing system full of accounts. There is a requirement that any new accounts are to be divided into "Funds". Initially two funds will be created. An account can be in either fund 1 or fund 2, and possibly both. We decided that a mapping table of funds and accounts be sufficient for this.
A front end instance can be logging into just one fund at a time.
Now comes the tricky part. We need to change the code to reflect this new behavior. We think replacing any select to the Account table with a view that joins on account and fund will do the trick. (it would return just the account rows specific to that fund)
When a user logs into the UI they will select the fund they want to view. What's the best option to allow the view to display the correct fund dynamically? Keep in mind the user could have two different instances open with different fund accounts. (we envision this to be default behavior for most users)
We want to avoid having to change the where clause in all our queries.
Any ideas?
Post #1363687
GSquared
GSquared
Posted Monday, September 24, 2012 1:07 PM
SSCoach
Group: General Forum Members
Last Login: Yesterday @ 1:55 PM
Points: 15,442,
Visits: 9,571
I'm not sure I follow you.
A View is just a saved Select statement. It can't be dynamic, really.
You can sort of do a dynamic view with an inline-table UDF, which is essentially a view with input parameters.
A stored procedure could take an input parameter of which type of account you want to look at, based on a value passed by the application, and could select different things from different objects (tables, views, UDFs) based on the inputs.
But I'm not sure if that's what you're trying to do or not.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #1363691
Mindy Hreczuck
Mindy Hreczuck
Posted Monday, September 24, 2012 1:49 PM
SSC Journeyman
Group: General Forum Members
Last Login: Monday, May 06, 2013 8:42 AM
Points: 79,
Visits: 478
Well I'll try to explain better...
One solution would be to create a UDF instead of a view and pass in a user guid into that UDF which queries the account table based on the fund mapped to that user guid.
This would require that all selects to the account table would be replaced by selects to the new account UDF, however all the procedures would need a new input parameter that accepts the current user guid to be passed into the UDF.
This is about as close as we as gotten to a "clean" solution, but its not ideal since we need to modify the code and procedure for the new input param.
Post #1363706
dwain.c
dwain.c
Posted Tuesday, September 25, 2012 9:05 PM
SSCrazy
Group: General Forum Members
Last Login: Today @ 3:20 AM
Points: 2,341,
Visits: 3,175
What you are asking about sounds like the Virtual Private Database concept available in Oracle Enterprise Edition.
I'm not sure if this link will help you or not but it is what I found on Google when I searched for an equivalent in MS SQL Server.
http://technet.microsoft.com/en-us/library/cc966395.aspx
No loops! No CURSORs! No RBAR! Hoo-uh!
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1364409
Lynn Pettis
Lynn Pettis
Posted Wednesday, September 26, 2012 1:01 AM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 1:46 PM
Points: 21,609,
Visits: 27,440
Mindy Hreczuck (9/24/2012)
Well I'll try to explain better...
One solution would be to create a UDF instead of a view and pass in a user guid into that UDF which queries the account table based on the fund mapped to that user guid.
This would require that all selects to the account table would be replaced by selects to the new account UDF, however all the procedures would need a new input parameter that accepts the current user guid to be passed into the UDF.
This is about as close as we as gotten to a "clean" solution, but its not ideal since we need to modify the code and procedure for the new input param.
If you post some DDL (CREATE TABLE statement) for the tables and some sample data (series of INSERT INTO statements) for each table, and the expected input/outputs maybe we could come up with something.
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #1364461
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.