Showing posts with label control. Show all posts
Showing posts with label control. Show all posts

Tuesday, March 20, 2012

Conditional WHERE statement?

Hi all,

I have one for all the blackbelters out there: is there a way i can
make a stored procedure where i can control the where statement with
variables? I have to do some complex transformations to get compose a
fact table for MSAS and there a a lot of similarities between the
queries and a few differences because of different account methods
etc. (booking in starting date, booking stuff on order entry dates
etc) I want to put a combination of different rules in different
members of dimensions.

An example of what i mean:

CREATE STORED PROCEDURE dbo.FILLFACT (@.PAR1, @.PAR2)
AS
INSERT INTO FactTable (blah blah)

SELECT
IF @.PAR1 = 'OrderDate'
SourceView.Orderdate
ELSE
SourceView.StartDate
,
etc etc...

FROM
SourceView

WHERE
IF @.PAR2 = 'WholeTable'
1=1
IF @.PAR2 = 'Incomplete'
EndDate IS NULL OR EXIST (SELECT * FROM Exceptions WHERE
..., etc)

This way i could fill my fact table with

EXEC dbo.FillFact 'beginDate','Wholetable'
EXEC dbo.FillFact 'begindate', 'Rulebook1'
EXEC dbo.FillFact 'BeginDate', 'Exceptions'
etcetera.

This is not an actual SQL script i use, just an example of what i'm
talking about. Or maybe i could pass the where statement entirley as a
variable? But i can't use SET @.PAR1 = 'EndDate IS NULL' and then use
WHERE @.PAR1 can I?

I hope i'm making sense. Does anyone know if this is possible? Right
now i have a procedure that is composed of a dozen of sql scripts that
are mostly the same, but i have to copy it for every combination of
situations and then, of course, new stuff has to be added on 12
different places. Again and again.

Any thoughts?

TIA,

Gert-Jan van der Kamp[posted and mailed, please reply in news]

G.J. v.d. Kamp (gjvdkamp@.hotmail.com) writes:
> I have one for all the blackbelters out there: is there a way i can
> make a stored procedure where i can control the where statement with
> variables? I have to do some complex transformations to get compose a
> fact table for MSAS and there a a lot of similarities between the
> queries and a few differences because of different account methods
> etc. (booking in starting date, booking stuff on order entry dates
> etc) I want to put a combination of different rules in different
> members of dimensions.

I believe that my article on dynamic search condition should give
you some ideas to work from. Look at
http://www.sommarskog.se/dyn-search.html.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||That's exectly what i mean, thanx!

Erland Sommarskog <esquel@.sommarskog.se> wrote in message news:<Xns95F2F1FFAE1DEYazorman@.127.0.0.1>...
> [posted and mailed, please reply in news]
> G.J. v.d. Kamp (gjvdkamp@.hotmail.com) writes:
> > I have one for all the blackbelters out there: is there a way i can
> > make a stored procedure where i can control the where statement with
> > variables? I have to do some complex transformations to get compose a
> > fact table for MSAS and there a a lot of similarities between the
> > queries and a few differences because of different account methods
> > etc. (booking in starting date, booking stuff on order entry dates
> > etc) I want to put a combination of different rules in different
> > members of dimensions.
> I believe that my article on dynamic search condition should give
> you some ideas to work from. Look at
> http://www.sommarskog.se/dyn-search.html.sqlsql

Sunday, March 11, 2012

conditional row output

Hi all,
is it possible to control row output on a report?
We are using MS Analysis Services Cubes as datasource and
experience some difficulties displaying ragged
hierarchies (parent child dimensions).
Reporting Services will create a subtotal for each group,
even if that group only contains a single item.
Is there a way to say "skip total when there is only one
item" ?
TIA Lutz MorrienYou might try to use a conditional iff
IIF, and the count function to count the members in the group. If the member
count > 1 show the field, else hide the field.
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Lutz Morrien" <anonymous@.discussions.microsoft.com> wrote in message
news:8ceb01c47878$521cbc00$a601280a@.phx.gbl...
> Hi all,
> is it possible to control row output on a report?
> We are using MS Analysis Services Cubes as datasource and
> experience some difficulties displaying ragged
> hierarchies (parent child dimensions).
> Reporting Services will create a subtotal for each group,
> even if that group only contains a single item.
> Is there a way to say "skip total when there is only one
> item" ?
> TIA Lutz Morrien|||Thank you Wayne,
it is indeed possible to control the visibility of a
field or a group using an iif construct.
Grouping on customer, I used the following:
=iif(count(Fields!Customer.Value)>1,True,False)
However, it seems that by hiding a group all groups
contained in this group plus all contained detail data is
hidden as well.
I just want RS not to calculate a total if there is only
one set of detail data. Hiding the detail data by hiding
the total is not really an option.
Thanks Lutz

Thursday, March 8, 2012

conditional look....

Hi;
is there a way to control the look of the printing based on the data?..
i want to change the look of a textbox in a table, based on the value in my
query, for example:
Job desc Name Income
Emply John 5000
Emply Peter 5000
Sup Hugo 5000
Emply Rich 5000
I want to change Font style to bold, when Job desc is Sup
Is there a way to do it?
TIAOn Apr 14, 10:09 am, "Willo" <willobe...@.yahoo.com.mx> wrote:
> Hi;
> is there a way to control the look of the printing based on the data?..
> i want to change the look of a textbox in a table, based on the value in my
> query, for example:
> Job desc Name Income
> Emply John 5000
> Emply Peter 5000
> Sup Hugo 5000
> Emply Rich 5000
> I want to change Font style to bold, when Job desc is Sup
> Is there a way to do it?
> TIA
Sure. While in the Layout view, select 'F4' (or the View tab and
Properties Window).Select the cell(s) in the table that you want to
change the font style for and in the Properties Window open up [+]
Font. To the right of 'Font Weight,' select the drop-down menu and
select '<Expression...>' and enter something like the following:
=iif(Fields!JobDesc.Value = "Sup", "Bold", "Normal")
Regards,
Enrique Martinez
Sr. Software Consultant

Wednesday, March 7, 2012

Conditional Formatting in a Matrix Control

Hi there.

I am creating a report that the requirements need different background colors based on the row or column as shown below:

Community Total # of Respondents Resident's Overall Satisfaction Rating Quality of Repair May '07 41 3.6 5.0 April '07 14 1.8 3.0 Q2 '07 55 2.7 4.0 March '07 36 3.6 3.0 February '07 28 4.0 1.2 January '07 22 2.2 4.0 Q1 '07 86 3.3 2.7 YTD '07 141 3.0 3.2 December '06 33 3.8 4.2 November '06 27 2.6 5.0 October '06 42 1.8 3.0 Q4 '06 102 2.7 4.1 September '06 58 4.0 2.2 August '06 84 2.0 1.6 July '06 52 3.2 3.4 Q3 '06 194 3.1 2.4 June '06 40 2.4 4.2 May '06 41 3.6 5.0 April '06 14 1.8 3.0 Q2 '06 95 2.6 4.1 March '06 67 N/A 3.8 February '06 38 N/A 2.8 January '06 N/A 3.8 N/A Q1 '06 105 3.8 3.3 YTD '06 496 2.9 3.5 Rolling 12 Month Average 477 2.9 3.3

'

I can get the row colors to work great with an expression, but when I try to add the gray column with conditional formatting for the Resident's Overall Satisfaction Rating question, it clobbers my row formatting. I am thinking that I will have to do some gnarly expression in each of the rows and columns using the InScope function. Does that sound about right, or is there an easier way?

Thanks, Mike

Actually, this was easy once I looked at it again. On the detail cell, I just added another condition that identified the column in question and set the color appropriately. Works great.

Sometimes it just takes another look!

- Mike

Conditional Formatting - Export

Using the web viewer control in VS 2005, is there a way to conditionally format items for export only?

For example, user runs a report which gets displayed in the viewer. The report contains small images and or decorated text for links to additional reports. If user selects pdf from the export dropdown list and clicks export, I would like hide the images in the pdf and or format the decorated text differently.

If the answer is no, is it due to the report already being in its intermediate state?

The answer to your first question is no. One way of getting close to the desired behavior is to either use different report definitions or use a report parameter to determine if images should be shown etc.

The answer to the second question is yes. When you export the report to PDF, it will just re-render the report from the already processed (and output-format independent) intermediate format.

-- Robert

Saturday, February 25, 2012

Conditional Execution in the Control Flow via Script Task

Greetings.

I'm trying to conditionally execute a dataflow based on the presence of a data file. If the data file isn't present, I'd like to execute gracefully without error.

Logic is as follows:

If FileExists Then
execute dataflow
Else
exit w/o error
End If

I've got the code ready to go, but I'm not sure how to do this conditional branch logic. Right now, the code calls the Dts.Results.Success / Failure. The problem, however, is Failure is exactly that... which doesn't result in the graceful exit I'm looking for.

Anyone have any ideas?

Thanks in advance.

Here is how I would do that:

Create a script task in your control flow to check if the file exists and write that result into a SSIS variable, let's say FileExists=1 -->exists; FileExtis=0 -->Does not exist. Then create a precedence constraint from the script task to the data flow. Then Edit the precedence constraint to use evaluation operation 'Expression and constraint'; Value 'success' and write the expression like @.[User::FileExists]==1.

This way the dataflow will be executed only if the sript task succed and the value of the variable FileExists is equal to one.

Rafael Salas

|||This sounds like a fantastic suggestion for the File System Task. I would suggest you submit it at the Microsoft Connect site.|||

Phil Brammer wrote:

This sounds like a fantastic suggestion for the File System Task. I would suggest you submit it at the Microsoft Connect site.

You mean to have a 'Check if file exists' operation in the file system task?

Rafael Salas

|||

Rafael Salas wrote:

Phil Brammer wrote:

This sounds like a fantastic suggestion for the File System Task. I would suggest you submit it at the Microsoft Connect site.

You mean to have a 'Check if file exists' operation in the file system task?

Rafael Salas

Indeed.|||

Good Idea. I followed your suggestion; for those interested in voting on that suggestion:

https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=231838

Rafael Salas

|||For those curious.. I documented the steps for future peoples that landed on this thread.

dichotic.wordpress.com

Conditional Control Flow element

Hi:

A branching element is critical to any process flow. Currently, as far as I know, there;s only a Conditional Split Data Flow Element. There is no direct way I can branch out in a control flow.

In some cases, I could branch by using a conditional operator ?: to either create a dynamic sql string for each patch, or a package name for a Package Execution task and so on.

This approach is not always good enough.

Are there others out there who want a Conditional Control Flow element?

TIA
Kar

Can't you use the normal constraints & change from "Constraint" to "Expression & Constraint" in the constraint properties, and then using variables for your branching, put your expression in the constraint? I've done this before to branch out the control flow.|||

karfast wrote:

Are there others out there who want a Conditional Control Flow element?

TIA
Kar

No, because expression-based constraints already exist in the control flow, which allow for what you desire.

Friday, February 24, 2012

Conditional Column Formatting

Hi Everyone,
I am trying to hide a column in a matrix table. I have no
trouble using conditional formatting to control the visibility of the
column, but when I hide the column the main row in the matrix does not
shrink. Therefore, I have a big gap... My thought was to use conditional
formatting to control the column width of the main matrix row. Listed
below is the expression that I used. Can anyone help me with the error
message or recommend a better solution?
=IIF(Fields!FiscalYear.Value = IIF(Month(TODAY()) = 10-12,Year(TODAY()) ,Year(Today())-1), 0.625in, 0.25in) cannot be
parsed as a unit because it does not contain numeric values. Examples
of valid unit strings are "1pt" and ".5in".
Regards,
A.AkinPut double quotes around the "0.625in" and "0.25in"
"awakin" wrote:
> Hi Everyone,
>
> I am trying to hide a column in a matrix table. I have no
> trouble using conditional formatting to control the visibility of the
> column, but when I hide the column the main row in the matrix does not
> shrink. Therefore, I have a big gap... My thought was to use conditional
> formatting to control the column width of the main matrix row. Listed
> below is the expression that I used. Can anyone help me with the error
> message or recommend a better solution?
>
>
>
> =IIF(Fields!FiscalYear.Value = IIF(Month(TODAY()) => 10-12,Year(TODAY()) ,Year(Today())-1), 0.625in, 0.25in) cannot be
> parsed as a unit because it does not contain numeric values. Examples
> of valid unit strings are "1pt" and ".5in".
>
> Regards,
>
> A.Akin
>|||That doesn't help. It still gives the same error message.
Is there another way of doing this?
"Michael C" wrote:
> Put double quotes around the "0.625in" and "0.25in"
>
> "awakin" wrote:
> > Hi Everyone,
> >
> >
> >
> > I am trying to hide a column in a matrix table. I have no
> > trouble using conditional formatting to control the visibility of the
> > column, but when I hide the column the main row in the matrix does not
> > shrink. Therefore, I have a big gap... My thought was to use conditional
> > formatting to control the column width of the main matrix row. Listed
> > below is the expression that I used. Can anyone help me with the error
> > message or recommend a better solution?
> >
> >
> >
> >
> >
> >
> >
> > =IIF(Fields!FiscalYear.Value = IIF(Month(TODAY()) => > 10-12,Year(TODAY()) ,Year(Today())-1), 0.625in, 0.25in) cannot be
> > parsed as a unit because it does not contain numeric values. Examples
> > of valid unit strings are "1pt" and ".5in".
> >
> >
> >
> > Regards,
> >
> >
> >
> > A.Akin
> >
> >|||Anthoney,
Did you ever figure this out? I need to control the width of a column but
it appears column width isn't formattable via an expression.
thanks,
Justin
"AnthonyG" wrote:
> That doesn't help. It still gives the same error message.
> Is there another way of doing this?
> "Michael C" wrote:
> >
> > Put double quotes around the "0.625in" and "0.25in"
> >
> >
> > "awakin" wrote:
> >
> > > Hi Everyone,
> > >
> > >
> > >
> > > I am trying to hide a column in a matrix table. I have no
> > > trouble using conditional formatting to control the visibility of the
> > > column, but when I hide the column the main row in the matrix does not
> > > shrink. Therefore, I have a big gap... My thought was to use conditional
> > > formatting to control the column width of the main matrix row. Listed
> > > below is the expression that I used. Can anyone help me with the error
> > > message or recommend a better solution?
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > =IIF(Fields!FiscalYear.Value = IIF(Month(TODAY()) => > > 10-12,Year(TODAY()) ,Year(Today())-1), 0.625in, 0.25in) cannot be
> > > parsed as a unit because it does not contain numeric values. Examples
> > > of valid unit strings are "1pt" and ".5in".
> > >
> > >
> > >
> > > Regards,
> > >
> > >
> > >
> > > A.Akin
> > >
> > >

Tuesday, February 14, 2012

Concurrency issues in stored procedures

I have a question regarding concurrency in stored procedures. I have a stored procedure with the following flow of control:

-- A couple of select statements here.

-- (placeholder - see below)

-- A couple of updates based on the data obtained
-- from the above select statements.

I'm concerned that while the stored procedure is running, if right when it gets to the spot in the code marked 'placeholder', the scheduling mechanism of SQL Server switches to another thread that contains requests from another client which makes changesto the data in the previous select statements. This will make my updates bad, since they rely on data (from the select statements)that has been modified.

I guess I'm curious what I would need to do to lock the records in the select statements until after my update statements are completed. Thanks in advance for any advice!

EverettBump

Concurrency Control

Hi! I'm building a web application with ASP.NET, and using MS SQL 2000 for my database server.

How should I do to guarantee the integrity of the data in spite of the concurrent access? Meaning... how can I make sure that more than 1 user can update 1 table at the same time, while no error will occur? Do I need to add some codes at my aspx file? Or do I need to do something to my database? Or do I not have to worry about it?

Thank you.

Well, from a database standpoint -- SQL server already has the abilityto deal with concurrent users, no modifications are necessary. Locksand other mechanisms make sure data updates don't interfere with oneanother. There are cirumstances where concurrent data access can causeproblems (deadlocks for instance), but these circumstances are rare.
So I guess the short answer is don't worry about it.
Jason

Concurrency Control

Hi! I'm building a web application with ASP.NET, and using MS SQL 2000 for m
y
database server.
How should I do to guarantee the integrity of the data in spite of the
concurrent access? Meaning... how can I make sure that more than 1 user can
update 1 table at the same time, while no error will occur? Do I need to add
some codes at my aspx file? Or do I need to do something to my database? Or
do I not have to worry about it?
Thank you.The easiest way is to use a rowversion (timestamp) type column. Look it up
in the books online for most of the details, but simply put, it is a
automatically maintained value that will change everytime your rows in your
database change. Then, as part of every update and delete of rows you have
cached, you can compare these values in the where clause and if they don't
match you knwo someone else has modified the row.
Then you just fetch the row back to the client and let them know what
changed.
----
Louis Davidson - drsql@.hotmail.com
SQL Server MVP
Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Blog - http://spaces.msn.com/members/drsql/
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)
"wrytat" <wrytat@.discussions.microsoft.com> wrote in message
news:12D9DA82-8D0B-451E-881F-6AAEE852DC14@.microsoft.com...
> Hi! I'm building a web application with ASP.NET, and using MS SQL 2000 for
> my
> database server.
> How should I do to guarantee the integrity of the data in spite of the
> concurrent access? Meaning... how can I make sure that more than 1 user
> can
> update 1 table at the same time, while no error will occur? Do I need to
> add
> some codes at my aspx file? Or do I need to do something to my database?
> Or
> do I not have to worry about it?
> Thank you.|||That all depends on what is actually needed. You have two viable choices in
my opinion:
1. Last write wins
2. First write wins
In the first scenario, the data from the person that makes the last write
call is the data that sticks. This is by far the easiest, but it has the
obvious downside of not informing the first user who just wrote their data
that their write was superceded.
In the second scenario, the data from the first person that writes to a row
sticks and an error is thrown for all other users. This is far more
complicated as you have to decide how to handle concurrency errors. Do you
let users choose whether to overwrite the data? Do you simply overwrite it?
Do you throw an error and force the user to re-enter their information? If
on a multi-row write, only of subset of writes fails, do you rollback all
writes?
As you can see, the second scenario is far more complicated to handle.
However, if you want to use the second scenario, then you need a way of
determining whether the row has changed since you last read the data. That
can be done in a couple of ways:
1. Timestamp. You add a timestamp column for every table that participates
in the First Write Wins scenario. For every write, you ask whether the
existing timestamp on the record is the same as the one you have when you
read the data. If they are different, you have a concurrency error,
otherwise write the data.
2. Other row version data type. Same solution as #1, except you use
something other than an actual Timestamp field. I have used Guids in the
past successfully.
3. You compare all fields you are trying to update with the values you had
on initial read. In order to really do this, you need to use dynamic SQL. It
is simply too cumbersome to try to handle with stored procs. The .NET
SqlDataAdapter does a passable job at this. There are also Object Relation
Mappers that will do this work for you or you can roll your own. Beyond not
being able to use stored procs, the other downside to this approach is that
the SQL statements can very long very fast, especially if some of the fields
are Text or Image.
4. Checksum. SQL has a checksum function that XOR the data in all the
columns to produce a quasi-unique number representing the contents of the
row. The catch is that SQL's checksum function does not account for Text or
Image columns.
IMO, you really need a very strong justification to going with First Write
Wins. The additional complexity added is significant and must be justified
by a high expected rate of collision and the absolute need for
user-consistency on all writes.
HTH,
Thomas
"wrytat" <wrytat@.discussions.microsoft.com> wrote in message
news:12D9DA82-8D0B-451E-881F-6AAEE852DC14@.microsoft.com...
> Hi! I'm building a web application with ASP.NET, and using MS SQL 2000 for
> my
> database server.
> How should I do to guarantee the integrity of the data in spite of the
> concurrent access? Meaning... how can I make sure that more than 1 user
> can
> update 1 table at the same time, while no error will occur? Do I need to
> add
> some codes at my aspx file? Or do I need to do something to my database?
> Or
> do I not have to worry about it?
> Thank you.|||in ado.net the concept of pessimistic locking is a bit difficult.
basically, ado.net only directly supports optimistic locking.
you'll need to read up on that in a good ado.net book.
sql server has concept of isolation level that you will likely want to read
up on. You can modify the Isolation level via ADO.NET via the sqlConnection
object.
Not to be taken lightly as High concurrency will yield low Consistency and
High consistency will yield low concurrency.
need to know what your application is doing and how tolerant it can be in
regards to dirty reads, etc.
study up. Also Load Test and Performance test Early and Often.
Greg Jackson
PDX, Oregon|||Thank you all of you. I've also read this article
(http://msdn.microsoft.com/library/d...ncychecking.asp) and learned a lot from it.
Then say if by default, I select the Optimistic Concurrency option in the
DataAdapter Configuration Wizard of the Visual Studio to handle Concurrency
Control. Do I still need to add a datetimestamp column to the database table
and compare the value of that column every time I update the table?
And must I also include the comparison of this columns for insert and delete
command as well? I guess the answer is no?
Anyway, someone told me that using SQL 2000 already provides the concurrency
control by default, such that even without ADO.NET, the amount of research o
n
concurrency control in SQL 2000 gurantees data integrity. I don't really kno
w
how true it is.
"pdxJaxon" wrote:

> in ado.net the concept of pessimistic locking is a bit difficult.
> basically, ado.net only directly supports optimistic locking.
> you'll need to read up on that in a good ado.net book.
> sql server has concept of isolation level that you will likely want to rea
d
> up on. You can modify the Isolation level via ADO.NET via the sqlConnectio
n
> object.
> Not to be taken lightly as High concurrency will yield low Consistency and
> High consistency will yield low concurrency.
> need to know what your application is doing and how tolerant it can be in
> regards to dirty reads, etc.
> study up. Also Load Test and Performance test Early and Often.
>
> Greg Jackson
> PDX, Oregon
>
>|||> Do I still need to add a datetimestamp column to the database table
> and compare the value of that column every time I update the table?
No, ADO.NET caches the values of *all* rows and compares the values against
*all* these rows. As far
as I can understand, you can customize this behavior.

> And must I also include the comparison of this columns for insert and dele
te
> command as well? I guess the answer is no?
No.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"wrytat" <wrytat@.discussions.microsoft.com> wrote in message
news:00E5B1E6-97E5-4997-8F7A-BF17E1641332@.microsoft.com...
> Thank you all of you. I've also read this article
> (http://msdn.microsoft.com/library/d...kin
g.asp)
> and learned a lot from it.
> Then say if by default, I select the Optimistic Concurrency option in the
> DataAdapter Configuration Wizard of the Visual Studio to handle Concurrenc
y
> Control. Do I still need to add a datetimestamp column to the database tab
le
> and compare the value of that column every time I update the table?
> And must I also include the comparison of this columns for insert and dele
te
> command as well? I guess the answer is no?
> Anyway, someone told me that using SQL 2000 already provides the concurren
cy
> control by default, such that even without ADO.NET, the amount of research
on
> concurrency control in SQL 2000 gurantees data integrity. I don't really k
now
> how true it is.
> "pdxJaxon" wrote:
>|||On Wed, 6 Apr 2005 20:23:15 -0700, Thomas wrote:
(snip)
>2. Other row version data type. Same solution as #1, except you use
>something other than an actual Timestamp field. I have used Guids in the
>past successfully.
Hi Thomas,
Why on earth would you do that?
A timestamp (aka rowversion) column takes 8 bytes, a uniqueidentifier
takes 16 bytes.
A timestamp column is changed automatically each time a row is inserted
or updated, a uniqueidentifier column is changed only when you
explicitly assign it a new value - so if you forget to, you'll miss the
change.
The timestamp datatype is designed explicitly for this goal, the
uniqueidentifier datatype is designed to be used as a surrogate key.
What is the advantage of using uniqueidentifier for concurrency control?

>4. Checksum. SQL has a checksum function that XOR the data in all the
>columns to produce a quasi-unique number representing the contents of the
>row. The catch is that SQL's checksum function does not account for Text or
>Image columns.
And another catch is that not all changes in the data result in a
different checksum. A different checksum guarantees changes, but an
unchanged checksum doesn't guarantee that the data is unchanged.
SELECT CHECKSUM('a'), CHECKSUM ('aaaaaaaaaaaaaaaaa')

>IMO, you really need a very strong justification to going with First Write
>Wins. The additional complexity added is significant and must be justified
>by a high expected rate of collision and the absolute need for
>user-consistency on all writes.
I couldn't disagree more. The risk of updates being overwritten without
anyone ever noticing is enough justification to take whatever steps are
necessary to prevent this in any serious business.
If you don't want the extra complexity, you should consider pessimistic
locking: get an exclusive rowlock when reading the data, keep the lock
as long as the data is displayed on the users' screen and only release
the lock after either the update is made or the user has decided to quit
the screen without saving changes. This will impact concurrency, but if
you expect very few collisions, it won't be a big deal. If you expect
lots of collisions, go for optimistic locking.
Never use Last Write Wins in any serious multiuser business application.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||On Wed, 6 Apr 2005 23:01:01 -0700, wrytat wrote:

>And must I also include the comparison of this columns for insert and delet
e
>command as well? I guess the answer is no?
Hi wrytat,
I have to disagree with Tibor's answer. You don't need it for inserts
(it's new data, so it can't be already locked), but you probably do need
it for deletes.
Example scenario: I start the application and show customer #123 on my
screen. You start the application and show the same customer. You see
that the information is outdated, find some new information in your
files and you make all changes to reflect the new status.Then you save
your data. Meanwhile, I see that this customre is outdated and I decide
that this old information might just as well be deleted. I hit delete.
The program will then happily delete the new information you just
entered for customer #123.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||> (snip)
<snip>
> What is the advantage of using uniqueidentifier for
> concurrency control?
The primary reason is that the calling code can generate the
new Id. It doesn't require an extra round trip to get the
updated Timestamp. The second reason is that mickeysoft has
already admitted that they are changing the Timestamp column
to be more inline with ANSI standards. Translation: It's
changing and I haven't the foggiest idea how compatitbility
will work. Lastly, and this was far more true in the past,
various development technologies did not always play nice
with Timestamps.

> And another catch is that not all changes in the data
> result in a
> different checksum. A different checksum guarantees
> changes, but an
> unchanged checksum doesn't guarantee that the data is
> unchanged.
> SELECT CHECKSUM('a'), CHECKSUM ('aaaaaaaaaaaaaaaaa')
Yep. It's far more problematic. You can of course roll your
own checksum to get around these problems, but it is a
option depending on how accurate the concurrency must be.

> I couldn't disagree more. The risk of updates being
> overwritten without
> anyone ever noticing is enough justification to take
> whatever steps are
> necessary to prevent this in any serious business.
It's a cost-benefit analysis. Does the substantial
additional development time for all development projects
justify the benefit of handling collisions? If there are few
collisions and the data involved is not that critical, then
it is not justified IMO. Finding other means of preventing
the collisions from happening in the first place is far
better choice if available.
Don't overlook the cost of handling first-write-wins
concurrency. Every system that touches the database has to
know how to deal with it. Every system has to potentially
present users with options about what to do in the case of a
collision. Situations like multiple row deletes (e.g. Delete
From Table Where ForeignKey = Value and thus multiple rows
would be deleted) are much more difficult if not impossible
because someone could have changed a row during the middle
of a delete. Isolation levels become much more of an issue
as some writes must be serialized which adversly affects
scalability. The list goes on. It basically becomes a
problem that has to be dealt with at all tiers of the
application.
It is a massive cost that, IMO, must be justified. Sometimes
it is. Most times it isn't.

> If you don't want the extra complexity, you should
> consider pessimistic
> locking: get an exclusive rowlock when reading the data,
> keep the lock
> as long as the data is displayed on the users' screen and
> only release
> the lock after either the update is made or the user has
> decided to quit
> the screen without saving changes. This will impact
> concurrency, but if
> you expect very few collisions, it won't be a big deal. If
> you expect
> lots of collisions, go for optimistic locking.
Pessimistic locking is even worse and should require an even
*more* extensive justification. There are places where it
makes sense, but they are extraordinarily rare IMO (SCMs are
a good example). Its biggest killer is scalability. Someone
locks a records and walks away from their desk. Now you have
to code timeouts and leases. It requires much more work and
hurts scalability.

> Never use Last Write Wins in any serious multiuser
> business application.
Nonsense. I have seen, and built myself, numerous
successful, large multiuser systems built with
Last-Write -Wins. They were designed such that collisions
could not happen or if, in the oft-chance they did, the
impact was minimal. The benefit of significantly shorter
development time more than justified the cost of an
occasional oddity due to collision.
Claiming that Last-Writes-Wins should never be used is
simply ignorant. It shows a blindness to other possiblities
that make First-Write-Wins unnecessary.
Thomas|||On Thu, 7 Apr 2005 13:20:45 -0700, Thomas wrote:
(snip major part of the post)
Hi Thomas,
Thanks for your post! I won't go into a debate. I think it's good that
both cases have now been defended. The OP can read both our posts,
weight the arguments and counter-arguments, decide how they apply in his
situation and then decide what works best for him. That's what I tried
to accomplish with my post.

>Pessimistic locking is even worse and should require an even
>*more* extensive justification. There are places where it
>makes sense, but they are extraordinarily rare IMO (SCMs are
>a good example). Its biggest killer is scalability. Someone
>locks a records and walks away from their desk. Now you have
>to code timeouts and leases. It requires much more work and
>hurts scalability.
I agree that pessimistic locking is worse than optimistic locking. I
would only consider using it for tables with extremely low update
frequency.
But it won't come as a surprise that I still think that pessimistic
locking is better (or rather: less bad) than Last-Write-Wins :-P
(snip)
>Claiming that Last-Writes-Wins should never be used is
>simply ignorant. It shows a blindness to other possiblities
>that make First-Write-Wins unnecessary.
Okay, I admit that this statement was too bold. I probably should have
written something along the lines of:
IMO, you really need a very strong justification to go with Last Write
Wins. The risk of losing relevant changes without any warning *and* the
consequences of such data should be weighed against the benefit of
reduced complexity and development costs. Because of the possible impact
of unnoticed data loss, this should ideally be a management decision.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)