Pros / Cons To This Approach

Nov 3, 2005

I have a requirement where I need to perform a query for position
information. But for some types of entries, I need to "expand" the row
to include additional position rows. Let me explain with an example:

An index is a security that is made up of components where each
component has a "weight" or a number of shares. So if I have 1 share of
the index, I have X shares of each component.

AAPL is an Equity, CSCO is an Equity, SPY is an Index. Lets say that
SPY has one component, AAPL, with shares being 10. (1 share of SPY = 10
shares of AAPL).

So, I do some trading and I end up with positions as follows:

+10 AAPL
-5 CSCO
+2 SPY

The query I need returns:

+10 AAPL
-5 CSCO
+2 SPY
+20 AAPL (from 2 SPY * 10 shares)

which becomes (after grouping):

+30 AAPL
-5 CSCO
+2 SPY

-----------------------------------------

Based on that criteria and the following schema (and sample data):

-- Drop tables
DROP TABLE [SecurityMaster]
DROP TABLE [Position]
DROP TABLE [IndexComponent]

-- Create tables
CREATE TABLE [SecurityMaster] (
[Symbol] VARCHAR(10)
, [SecurityType] VARCHAR(10)
)

CREATE TABLE [Position] (
[Account] VARCHAR(10)
, [Symbol] VARCHAR(10)
, [Position] INT
)

CREATE TABLE [IndexComponent] (
[IndexSymbol] VARCHAR(10)
, [ComponentSymbol] VARCHAR(10)
, [Shares] INT
)

--Populate tables
INSERT INTO [SecurityMaster] VALUES ('AAPL', 'Equity')
INSERT INTO [SecurityMaster] VALUES ('MSFT', 'Equity')
INSERT INTO [SecurityMaster] VALUES ('MNTAM', 'Option')
INSERT INTO [SecurityMaster] VALUES ('CSCO', 'Equity')
INSERT INTO [SecurityMaster] VALUES ('SPY', 'Index')

INSERT INTO [Position] VALUES ('001', 'AAPL', 10)
INSERT INTO [Position] VALUES ('001', 'MSFT', -5)
INSERT INTO [Position] VALUES ('001', 'CSCO', 10)
INSERT INTO [Position] VALUES ('001', 'SPY', 15)
INSERT INTO [Position] VALUES ('001', 'QQQQ', 21)
INSERT INTO [Position] VALUES ('002', 'MNTAM', 10)
INSERT INTO [Position] VALUES ('002', 'APPL', 20)
INSERT INTO [Position] VALUES ('003', 'SPY', -2)

INSERT INTO [IndexComponent] VALUES ('SPY', 'AAPL', 25)
INSERT INTO [IndexComponent] VALUES ('SPY', 'CSCO', 50)
INSERT INTO [IndexComponent] VALUES ('QQQQ', 'AAPL', 33)

-- *****************************

-- Based on the rules:
-- 1) Index positions appear like other positions (account /
symbol) pair, but
-- its components show up as new rows of account (of index),
symbol (equal
--to component symbol), position (equal to shares * index position)
-- 2) One row for each account / symbol pair (GROUP BY account and
symbol, SUM position)

-- Expected output (without grouping) (sorted by account / symbol)
-- 001 AAPL 10
-- 001 AAPL 375 (component shares * index position) (25
* 15) (SPY)
-- 001 AAPL 693 (component shares * index position) (33
* 21) (QQQQ)
-- 001 CSCO 10
-- 001 CSCO 750 (component shares * index position) (50
* 15) (SPY)
-- 001 MSFT -5
-- 001 QQQQ 21
-- 001 SPY 15

-- 002 AAPL 20
-- 002 MNTAM 10

-- 003 AAPL -50 (component shares * index position) (25
* -2) (SPY)
-- 003 CSCO -100 (component shares * index position) (50
* -2) (SPY)
-- 003 SPY -2

-- Expected output (with grouping account / symbol) (sorted by account
/ symbol)
-- 001 AAPL 1078
-- 001 CSCO 760
-- 001 MSFT -5
-- 001 QQQQ 21
-- 001 SPY 15

-- 002 AAPL 20
-- 002 MNTAM 10

-- 003 AAPL -50
-- 003 CSCO -100
-- 003 SPY -2

---------------------------------------------

Is a UNION the best way to perform the query. What are the pros and
cons? What, if any, is a better way?

SELECT
[Account], [Symbol], SUM([Position]) AS [Position]
FROM
(
SELECT[Account], [Symbol] , [Position]
FROM[Position]

UNION ALL

SELECTP.[Account] , IC.[ComponentSymbol] AS [Symbol] , (P.[Position] *
IC.[Shares]) AS [Position]
FROM[IndexComponent] IC
JOIN[Position] P
ONP.[Symbol] = IC.[IndexSymbol]
) D
GROUP BY[Account], [Symbol]
ORDER BY[Account], [Symbol]

View 5 Replies


ADVERTISEMENT

SQL Server Pros And Cons

May 22, 2002

My company is thinking about moving to a product that uses Microsoft SQL Server and I have been asked to find out what are the Pros and Cons of the product, if any.

Any feedback is appreciated.

Thank You

Pam

View 2 Replies View Related

Upgrade SQL 7 To SQL 2K: Pros And Cons

Aug 13, 2001

Anyone know where I could find some good articles about pros and cons of upgrading SQL 7 to SQL 2K?

Our boss suddenly got this bug up his rear that we need to upgrade. :(
Probably because we are to a point where everything is running smoothly, and he needs to throw a monkey wrench in it.

We are a very small shop, and are not stressing SQL 7 in the least. I am interested to read some articles about SQL 2K, because right now, I can't see any possible reason an upgrade would be worth doing.

Thanks.

View 2 Replies View Related

UniqueIdentifier Pros And Cons ??

Jul 20, 2005

Hi alli am building a SQL 2000 database that it is proving a littlechallenging, i have companies with multiple addresses, phone numbers,owning mine sites etc and also joint ventures so maybe you get thepicture with a few design issues that i ma encounteringMy queriy is about a primary key identity, and which one to use withrespect to either the identity data type or the unique identifier ,I am aessentiall building an address table to hold all multipleaddresses as well as phone numbers etc, so my desire to have a uniqueidentity for each record is very important.My view is i will run in to violation errors by just using the tableidentity data type, i could i suppose use composit primary keys butthat may have a performance impact, although thiis will not be a hightransaction database.Does anyone know about performance issues regarding each identitysolution, by using a generated 16 bit identifier there are going to behuge numbers for the DB to verify. or am i worried about nothing?any views greatly appreciatedregardsGreg

View 17 Replies View Related

Pros And Cons Of Stored Procedures

Mar 28, 2004

can anyone explain the Pros and Cons of Stored Procedures ??

thanks

View 2 Replies View Related

Pros And Cons Of Using Stored Procedures

Sep 19, 2007

Im about to start converting code to Stored Procedures for all my reports in Reporting Services. I was wondering what the pros and cons of this may be.

View 17 Replies View Related

Network Backup Again - What Are The Pros And Cons

Sep 11, 2007

Thanks for the help on the previous thread.

It seems to me that either by accident or design, SQL Server tends to steer you away from backing up directly over the network.

Are there reasons for not doing this because you obviously don't want to leave your backups on a local drive in case the drive fails?

Some possibilties that I can think of are:-

1. Local drives have faster access times and SQL backups can get quite large. I did a quick test and found that a netwrok backup takes 2 to 3 times longer than it does on a local drive.
2. Backing up on the netwrok could hog too much bandwidth. I haven't tested this and would be surprised it it's true.
3. There could be some reason that you don't want the Server and Agent services running under a domain account but want to leave them on the Local System account. I am not aware of any such reasons by the way.
4. Local drives persumably have a slightly higher availability than network drives. If the server is running, the drive should be available.

View 8 Replies View Related

What Are The Cons And Pros Of Using Nvarchar(max) Versus Ntext?

Apr 4, 2007

Like in the subject: What are the cons and pros of using nvarchar(max) versus ntext?
Does it have something to do with having to enable full text search perhaps in the latter case?

View 2 Replies View Related

Pros/Cons Of Multivalue Database Columns

Jun 27, 2004

I'm just wondering what any pros and cons of using multivalue columns in a database are.

I'm designing a database which will have a column for FABRIC_TYPES_AVAILABLE for a certain FURNITURE_ITEM. Each FURNITURE_ITEM can have multiple FABRIC_TYPES_AVAILABLE of course. So I was just going to store a 2 or 3 digit number of the FABRIC_TYPES_AVAILABLE in that row. So I would have something like....34,24,453,32,23,45,67,65,43,21,21,45.

Anyway....thanks in advance for any information. Links I could read would be great too...b/c I did do a bit of searching, but didnt find much.

View 6 Replies View Related

PROS And CONS Of Seperate Databases For CACHING...

May 9, 2006

I have a main database...for this large Web site...and Im wondering
what would be the PROS and CONS of using another database (located on
the same, or on another SQL Server). Im just thinking this would be
good incase we ever needed to take some load off one of the servers.

Also, we will be integrating Community Server into this Web site. Of
course you know CS adds its own database objects which crowd up our
main database objects.

We were thinking of giving CS its own database also; bad practice, or....it doesn't matter much?

Thank you

View 3 Replies View Related

GUID Pros And Cons (was: Question Mssql2005)

Aug 17, 2006

I was wanting to know. I am making a site that might be come big. And me and this dude are considering pickering abotu GUID. I don't want to use them but he does. And I was wondering what should we do? I know nothing about guids

View 1 Replies View Related

Query Excution Process- Pros And Cons

Jun 15, 2006

vinod writes "Q1>Should I apply filter in sequence(based on primarykey,not null,comparision,between clause) ?

-How to apply filter in correct format,and SQL server internally execute it.
Q2>Should I use 'is not Null' to be put at the last?

Q3>Should I use 'between clause' rather than relation operator i.e(empid>10 and empid<200)

Q4>Does filters of sequence has any impact on the query execution process


table1[pkey1,col1,col2,col3] -->pkey is pkey1
table2[pkey2,pkey1,col11,col12,col13]--->pkey is pkey2, and pkey1 is foreign key

CaseI->select table2.pkey2,table1.col1 ,table2.col12
from table1 inner join table2
on table1.pkey1=table2.pkey1
where (table1.col3>100 and table1.col3<300 ) and table2.pkey1=2020 and table2.col13 is not null

CaseII->select table2.pkey2,table1.col1 ,table2.col12
from table1 inner join table2
on table1.pkey1=table2.pkey1
where (table1.col3 between 101 and 299 ) and pkey1=2020 and table2.col13 is not null"

View 1 Replies View Related

Default Constraint On Columns Pros And Cons?

Oct 26, 2007



Are there any vices to using default constraints on all columns in your table.
For example an Int that defaults to 0
or a char or varchar that defaults to ''

I know that 0 and Null are not the same thing. But if your programs don't have the concept of NULL then you have to convert the NULL to zero.

So, DEFAULT CONSTRAINTS on every column. Is it good or Bad?

Thanks

Darin Clark

View 10 Replies View Related

Saving Files (Binaries) Into Database - Pros And Cons

Jun 19, 2008

Can someone provide information or a link to information regarding the pros and cons of saving files directly into a SQL 2005 database?
I'm actually for saving files to a database (cleaner implementation then just saving the location then having to get the file, etc), but my project manager is not convinced so I need to make an argument for (or against depending on what I actually find out) using varbinary data type.
Thanks.

View 2 Replies View Related

What Are Cons And Pros For Using IDENTITY Property As PK In SQL SERVER 2000?

Jul 20, 2005

Hi All!We are doing new development for SQL Server 2000 and also moving fromSQL 7.0 to SQL Server 2000.What are cons and pros for using IDENTITY property as PK in SQL SERVER2000?Please, share your experience in using IDENTITY as PK .Does SCOPE_IDENTITY makes life easier in SQL 2000?Is there issues with DENTITY property when moving DB from one serverto another? (the same version of SQL Server)Thank you in advance,Andy

View 49 Replies View Related

Storing SSIS Packages Within SQLServer; Pros/cons

Feb 26, 2008

hi all,
I was wondering if anyone knows of any pros/cons on storing SSIS (2005) packages within SQL Server 2005 SP2.
We're contemplating the migration/storage of a large number of packages, a minority of which designed in dts (SQLServer 2000) and using third party activx components.

thanks much for any feedback,
Cosmin

View 3 Replies View Related

Pros And Cons Of Placing Indexes On Separate File Groups

Apr 20, 2001

We are in the process of replacing our primary production server. In the process of determining how SQL server is going to be structured, it has been suggested that I place all current and new indexes on a separate file group. These filegroups would then reside on a separate shelf on the server. What are the pros and cons of doing this?

View 2 Replies View Related

Pros And Cons Of Using Transaction Replication Doing Initialization From Database Backups

Jun 27, 2007



I am using transaction replication between a transaction and reporting database server. When I use a snapshot to initialize my subscribers, I currently get a lot of deadlocks during the snapshot creation. I am considering using a database backup instead. Can anyone tells me how to reduce the table locks that I am getting during snapshot creation or advice on using database backups?



View 1 Replies View Related

Need Help With Project $$ Pros Only

Mar 30, 2008

Hi, I need a help with a SP, professionals only. If you're interested PM/email me please.

View 3 Replies View Related

Maybe Trigger Failed, Deadlock Victim? Pros Click Me!!!

Mar 10, 2000

Let's say I have a trigger on my orders table.

When this fires a query is done on the customer table to get some values
and put some order/customer data into an audit trail table.

In one period of time, it appears that the trigger did not put the data into the separate table. No known reason.

Suspicion: What if the customer table were locked by some process when the trigger fired. Maybe the trigger was chosen as a deadlock-victim.

?? I guess I need to check for @@ERROR during the trigger and do something. Any suggestions? I think I can raise the priority of my trigger to "win" during a deadlock.

If trigger activity is chosen as a deadlock-victim, can the trigger make another attempt to complete it's activity?

View 1 Replies View Related

Best Approach With DTS

Mar 30, 2004

Let me see if I can explain this.

I have the need to pull data from multiple tables from a DB2 system via ODBC and update or insert as needed into tables in a SQL200 DB.

Step 1.
The data from the initial parent table will need to be limited to being a set number of days old, which I have in place and working.

Step 2
The next tables data needs to be limited from the data retrieved in step 1 (I’d like to use the paprent table retrieved in step 1, that is in SQL now, rather than doing it on the DB2 side.

Step 3
The returned rows here, need to be limited to key values returned from step 2

Additional steps apply, but nearly all will be limited to the results of parent tables from the prior step.

What is the best approach to this? I really want to pull table A to SQL, and limit the next child set from Table A, that was pulled to SQL in the prior step.

I also need to do updates rather than dropping and creating the needed tables each time. Insert if no key exists, etc .etc.


What is the best approach?

View 2 Replies View Related

Best Way To Approach This

Mar 20, 2006

I've been working on this project, and had it working in MySQL, but it was badly done and couldn't last more than a few hours without growing so large that everything slowed way down. I don't expect anyone to tell me exactly what to do, just please provide an outline of what the best way to approach this in SQL Server 2005 is.

To simplify it, I have one table "Items" and another table "ItemPrices". Items has an id and a name. Each row in ItemPrices has an id for the item, a price and two datestamps (added, last updated).

On average, there's about 15,000 active items, 50% of them have new prices every couple minutes, so I'm looking at what seems like a ton of data being constantly imported. There's probably a good way to do this but I only know the bad way :)

So.. what I want to be able to do is have maybe a stored procedure (?) that takes the item name and price as parameters. (In MySQL I was using "INSERT... ON DUPLICATE KEY UPDATE")
A. If it's a new item name, it will add a row to the Items table and a row to ItemPrices
B. If it's an existing item with the same price as the current price (the most recent price for that item in ItemPrices) it will update the "last updated" date field
C. If it's a new price it will insert a row into ItemPrices for that item

Also, I want historical pricing data, but if I ever release this, 95% of the users will just be looking at current prices. I need the current prices to be very fast to query, in my MySQL version I was using something like this: "SELECT... join on lastupdated=(SELECT Max(lastupdated) FROM ItemPrices ...", after I had 300k price updates querying a list of items took like 15 seconds.. there's got to be a better way? What should I do to make this faster?

Does this make any sense? Hopefully someone can lead me in the right direction. Thank you very much!

View 3 Replies View Related

Appropriate MDX Approach ???

May 24, 2008



Hello all.


I use MDX on a cube which provides data about animal population.


The cube contains the keyfigure "ANIMALS" that takes the number of animals.

The cube has a dimension "VERSION" which is used to identify the keyfigure
as a target or an actual value (possible values: "actual" and "target")
The cube has another dimension "ZONE" for the population zones.
Possible values for zones: "A", "B", "C" and "D".


Now I want to create an MDX statement, that gives me a result row like this:

Actual number of animals (as sum of all 4 zones) in column no. 1,
Target number of animals (as sum of all 4 zones) in column no. 2,
Achieved percentage (as actual number / target number * 100) in column no. 3.


Until here my statement works and it looks like this:


WITH MEMBER [VERSION].[achieved] AS '[VERSION].[actual] / [VERSION].[target] * 100'
SELECT {[VERSION].[actual], [VERSION].[target], [VERSION].[achieved]} on COLUMNS
FROM [$MYCUBE]
WHERE ([Measures].[ANIMALS])


It surely is possible that the achieved value for all zones together is equal to or greater than 100%,
while single zones might have an achieved values less than 100%.


In order to account on this, i would like column no. 4 to display one of these words:
"ok" if none of the single zones has an achieved value smaller than 100%,
"warning" if any of the single zones has an achieved value between 96 and 99%,
"alert" if any of the single zones has an achieved value smaller than 95%.


That means, i want e.g. the word "yellow" if the lowest achieved value
of the 4 zones is between 96 and 99. I want to have "red" if the lowest value
is smaller than 95.


I am quite new to MDX and I have struggled quite a long time with this.
I would be grateful for a hint on how i have to modify / enhance my MDX statement.


Regards. Peter.

View 1 Replies View Related

Best Approach

Sep 27, 2006

I have what I feel like is a simple package I am working to create. I am teaching myself SSIS as I go along.

Source server SQL 2000 database allows NULL values in columns.

Destination Server also SQL 2000 but the database required a value in each column.

So I do a basic source select what I want. I next need to read the values and determine if null then insert a space, do some column matching and insert them into the destination sever.

I believe I should use a Derived Column and an expression ISNULL to accomplish what I want.

Maybe there is a better way. Suggestion and comment appreciated.

Ryan


View 1 Replies View Related

Help With Using The Right Approach

May 18, 2006

Greetings my friends

I am attempting to solve the following problem using SSIS, actually I am attempting to convert a SQL Server 2000 DTS package in to a SSIS package.

The package does the following :

1) Retrieve the maximum Price_ID (PK) from a PRICE dimension table.

2) Populate a staging table with data coming from a source system where the PRICE_ID > (Price_ID from above)

3) Update the actual DIM table with the new data help in the staging table.

For this task I want to learn the use of the Lookup component which I think is appropriate.



My questions are as follows :



If I create a global variable to hold the maximum PRICE_ID (see point 1). How do I get to use the variable in the my Data Flow Data source?!



I am totally confused... I don't even know where to start with this.



Your help would be appreciated.



Thanks SQL friends.

View 6 Replies View Related

Best Approach

Jun 21, 2006

I've been banging my head for a while now, and it is sore! :-P

I'm a best practice/Microsoft approach type of person and want to make sure I do things correctly.

I have a database, kind of like a forum.



Obviously executing multiple queries in one "batch" (stored proc) would have an impact on the performance.



Now, I would like to give a more detailed/specific error back to the caller (either by aid of error code or whatever) with such situations like...

"EditReply"

Edit reply takes the threadID, replyID and userID.

Before actually commiting the changes, it needs to check:

1) does the user exist in the database? (during the editing of the reply, perhaps the user may have been deleted before running the stored proc, who knows)

2) does the thread exist?

3) does the reply exist?



if the conditions are met, only then will it go ahead and update the database. Now that is 3 queries, and 4 statements overall to make a change to a field/table.



Obviously if one of the commands returns false, in other words if say "does the thread exist" returns 0 (thread doesnt exist) it will return back to the caller an errorcode, which they will handle in their application. Thats all fine but the question is



Am I doing this correctly? (no) - how can I improve this? What do I need to think about?

Of course I would like to give a more detailed error back to the caller (aid of errorcode designed in the application overall) instead of just "no, databases not updated".



In this situation, am I wrongly assuming that the database designers use this type of approach?



Please help, I value your feedback and suggestions. I want to improve and think of the right lines of doing these things.

View 12 Replies View Related

SqlBulkInsert ?? Or Better Approach?

Aug 7, 2006

Hello,

I'm doing my best here, but need some help. I have a client that has a company list that they want searched by key word. This is exported from another program (in excel) that they want used and searched on their website.

Bad news, is each Keyword is listed with the company separately. So if a company has 5 different key words, they will be listed in the excel file 5 times.

The info I have is Name, Address, City, State, Phone, Keywords:

So example of excel is:Company A, 123 Main St, Mycity, Mystate, 123-123-1234, Green
Company A, 123 Main St, Mycity, Mystate, 123-123-1234, Furry
Company A, 123 Main St, Mycity, Mystate, 123-123-1234, Large
Company A, 123 Main St, Mycity, Mystate, 123-123-1234, Circular
Company B, 746 Sparrow Ave, Diffcity, Diffstate, 987-987-9876, Blue
Company B, 746 Sparrow Ave, Diffcity, Diffstate, 987-987-9876, Furry
Company B, 746 Sparrow Ave, Diffcity, Diffstate, 987-987-9876, Small

I am able to import this large (4.2 MB) file into a table called fctable

What i'm trying to do is write SQL scripts or queries that can insert into a Company Table and Keyword Table.

I'm trying to write this through asp.net 2.0 (so the excel file is uploaded) and have tried to write my inserts like

INSERT INTO [Company] ([Name], [address], [City], [State], [Phone]) VALUES (SELECT DISTINCT
Name, Address, City, State, Phone
FROM fctable )

But that doesn't seem to be working.

This is the only way my client can get the info to me, and it will be changed probably twice per month, so I'd hate to have to try to manipulate an excel file 24 times a year to import.

Any suggestions Appreciated

View 2 Replies View Related

SQL OPENXML: Best Approach

Feb 27, 2008

Hello everyone.
I am new to.Net and here is what I have to do.
 I needto update a SQL table with data coming from a XML file.  I have seen some Microsoft documentation on this (the nice SQL statement that updates and inserts in the same stored procedure) but I don'tknow what is the best approach for passing my XML file to the stored procedure.  The XML contains about 12 000 records, kind of phonebook info (name, email, phone).
 What would be the best approach to do this?  What objects should I use?
 Thanks a million,
Ben
 

View 2 Replies View Related

MS SQL Server 7.0 And Approach

Oct 18, 1999

Environment
NT Server 4.0 w/ SP4
SQL Server 7.0 w/ SP1
Win98 Client w/ Lotus Approach 9.5

I recently added SQL 7.0 to be a back end for my Approach front end. I transferred all the data from a dbase IV in approach to SQL. Most of the conversions worked ok. I have two big problems.

1) One particular repeat panel in Approach loses the children records of the master record. If I delete some of the records, more will appear. It's as if there is an imaginary limit of the number of records it can read in the repeat panel. I don't have this problem with any other records and children in repeat panels. I called Lotus and they don't have an answer. This is important because the children records need to be summed up so I can have a running total.

2) I original configured the clients to use the TCP/IP Netlib w/ the default port. I couldn't open enough databases so I changed to Multiprotocol. This allowed certain clients to open more databases, but others can't open additional databases. Also, after the change, the NT authentication login has had problems. I had to change to the SQL login to get all my clients back on line. Sometimes the same client can't open more than 10 databases while other times it will open 15. There is no consistent patten to when it can and can't open the additional databases.

If anyone knows how to fix either of these problems, I would greatly appreciate any advice. I'm getting tired of my boss yelling at me.

Thanks.

Keith
akumaboyz@aol.com

View 1 Replies View Related

Not Sure How To Approach This, If /then Select?

May 12, 2008

I have a select statement where I need to test two values that are returned and perform a different calculation if they return null.

Basically,
if TESTA is null and TESTB is not null
return TESTB

if TESTB is null and TESTA is not null
return TESTA

ELSE if both are not null
TestA + TestB / 2 is value is returned

is this possible to do in a select statement? thanks in advance.

See select statement below:

Select S.StudentDimKey,
(select ISNULL(R.Score, NULL) from CLT_StudentAssessmentRawFact R, CLT_LessonPlanDim L where L.LessonPlanKey = 1 and L.LessonPlanDimKey = R.LessonPlanDimKey and StudentDimKey = S.StudentDimKey) as TESTA,
(select ISNULL(R.Score, NULL) from CLT_StudentAssessmentRawFact R, CLT_LessonPlanDim L where L.LessonPlanKey = 2 and L.LessonPlanDimKey = R.LessonPlanDimKey and StudentDimKey = S.StudentDimKey) as TESTB,
from CLT_StudentPlacementFact P, CLT_StudentDim S, CLT_ClassHierarchyDim H, CLT_StudentClassFact C
where P.StudentDimKey = S.StudentDimKey
and H.ClassHierarchyDimKey = C.ClassHierarchyDimKey
and S.StudentDimKey = C.StudentDimKey
and S.StatusCode = 'A'
and S.CurrentRecord = 1
and S.SchoolID = 87577

View 2 Replies View Related

Can A Set Based Approach Help Me Here...

Feb 1, 2007

im practicing set based approaches... and what im trying to do is grab each value from a table , scramble it and put it back in the table... i dont want the solution to this as id rather figure it out myself for practice...

the thing im stuck at is i can do this with a cursor but i want to avoid cursors in future, how would i use a set based approach to get each value of a table and work with it?

View 4 Replies View Related

Set Approach Instead Of Cursor

Jul 20, 2005

Hi,I am trying a Set Approach instead of Using of Cursor (which works).I am attaching the SQL to create tables and the my Procedure, and apiece of code to execute the Procedure.I would like the Procedure ReplaceTags to work with 'a' the same aswith 'C'.Thanks in advance.Hareesh/*****************************//* Create Tables */IF EXISTS (SELECT * FROM dbo.sysobjects WHERE ID =OBJECT_ID(N'GlobalTags') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)DROP TABLE GlobalTagsGOCREATE TABLE GlobalTags(Project VARCHAR(50) NULL,TagName VARCHAR(50) NULL,[Value] VARCHAR(50) NULL)GOIF EXISTS (SELECT * FROM dbo.sysobjects WHERE ID =OBJECT_ID(N'ProductDetails') and OBJECTPROPERTY(id, N'IsUserTable') =1)DROP TABLE ProductDetailsGOCREATE TABLE ProductDetails(Project VARCHAR(50) NULL,KeyName VARCHAR(50) NULL,[Value] VARCHAR(50) NULL)GO/*********************************//* Populate Tables */TRUNCATE TABLE GlobalTagsINSERT INTO GlobalTags (Project, TagName, Value)VALUES('ProjectName', 'FirstName', 'John')INSERT INTO GlobalTags (Project, TagName, Value)VALUES('ProjectName', 'LastName', 'Doe')INSERT INTO GlobalTags (Project, TagName, Value)VALUES('ProjectName', 'PhoneNo', '5248')INSERT INTO GlobalTags (Project, TagName, Value)VALUES('ProjectName', 'ZIPCode', '55555')TRUNCATE TABLE ProductDetailsINSERT INTO ProductDetails (Project, KeyName, Value)VALUES('ProjectName', 'FirstName', '%FirstName%')INSERT INTO ProductDetails (Project, KeyName, Value)VALUES('ProjectName', 'LastName', '%LastName%')INSERT INTO ProductDetails (Project, KeyName, Value)VALUES('ProjectName', 'PhoneNo', '%PhoneNo%')INSERT INTO ProductDetails (Project, KeyName, Value)VALUES('ProjectName', 'ZIPCode', '%ZIPCode%')/****************************//* Procedure */IF EXISTS (SELECT * FROM sysobjects WHERE name = 'ReplaceTags')DROP PROCEDURE ReplaceTagsGOCREATE PROCEDURE ReplaceTags(@aProjectName VARCHAR(50),@aProcessType CHAR(1))ASBEGINDECLARE @TagName VARCHAR(50)DECLARE @Value VARCHAR(50)IF @aProcessType = 'C'BEGINDECLARE REPLACE_CURSOR CURSOR FAST_FORWARD READ_ONLY FORSELECT TagName, Value FROM GlobalTagsWHERE Project = @aProjectNameOPEN REPLACE_CURSORFETCH NEXT FROM REPLACE_CURSOR INTO @TagName, @ValueWHILE (@@FETCH_STATUS = 0)BEGINUPDATE ProductDetailsSETValue =CASE WHEN CHARINDEX('%' + @TagName + '%', Value, 1) > 0THENREPLACE(Value, '%' + @TagName + '%', @Value)ELSEValueENDWHERE Project = @aProjectNameFETCH NEXT FROM REPLACE_CURSOR INTO @TagName, @ValueENDCLOSE REPLACE_CURSORDEALLOCATE REPLACE_CURSORENDELSEBEGINUPDATE ProductDetailsSETValue =CASE WHEN CHARINDEX('%' + GlobalTags.TagName + '%',ProductDetails.Value, 1) > 0 THENREPLACE(ProductDetails.Value, '%' +GlobalTags.TagName + '%', GlobalTags.Value)ELSEProductDetails.ValueENDFROM ProductDetails INNER JOIN GlobalTagsON (ProductDetails.Project = GlobalTags.Project)WHERE ProductDetails.Project = @aProjectNameENDEND/***********************************//* Run Procedure */EXECUTE ReplaceTags 'ProjectName', 'a'-- EXECUTE ReplaceTags 'ProjectName', 'C'SELECT * FROM GlobalTagsSELECT * FROM ProductDetails/* End*//***********************************/

View 6 Replies View Related

Should I Use A Trigger Or A Different Approach?

Apr 25, 2008



Lets say I have a dynamic table of 10 to 30 varchar(255) columns that I do not know the names of.



Each of these columns is updated with either an 'OK' or an error msg.



Here's the issue. I have a Status column (varchar(MAX)) which I want to be the concatenated sum of all the other columns. I'd like to do this via a trigger because the way I understand it, theres no way a trigger can skip over another update/trigger and write the wrong 'Status' value.



Example Row 1:

RandomColName1 = "1||Access Denied"

RandomColName2 = "0||OK"

RandomColName3 = "2||ID10T Error at Kbrd"

Status = "[RandomColName1] Access Denied | [RandomColName3] = "ID10T Error at Kbrd"



Example Row 2:

RandomColName1 = "0||OK"

RandomColName2 = "0||OK"

RandomColName3 = "0||OK"

Status = "0||OK"



The rules:

1. There is no chance of someone updating the same column at the same time.

2. There's a good chance that other columns in the same row will be updated at the same time.

3. Sometimes a column can be updated every 5 secs.

4. About 100 to 5000 Rows



I'm a SQL newb and this would be my first trigger to write (lol) but I feel if it could be done without causing a DEADLOCK then it should be done this way. Unless someone with more experience can shed some light



With up to 300 .net clients over fast and slow links, I don't want to xfer the whole 5000 row / 50 column table back to the app and have it weed it out, especially if the client only needs 100 of the rows. On the same token, I don't want to make an individual call back to the SQL server should the client need 4000 rows.
Thanks for the help!

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved