|
Posted by Erland Sommarskog on 10/02/71 11:47
Amb (ashleymtnbarnes@hotmail.com) writes:
> GN: Eg: To get the balance in a banking app.
> create table Test
> (
> Client varchar(10),
> Bal money
> )
> GO
> insert into test values ('1',10)
> GO
> declare @bal money
> declare @addition money
> select @addition = 100
> update test set @bal = bal = bal + @addition
> select @bal
> [/end]
>
> The above example is clearly more advanced than the first, but it
> works. The thing is that if it isnt supported, then why is it being
> taught at the Tech Ed conferences? GN went on to specify that the
> method as shown above in Malc's post was taught as a way of doing a
> single field pivot.
But this example is different from what Malc asked about. Here @bal
appears only to the left. So this example should be fine.
It's when you have
SELECT @x = @x + col
or
UPDATE tbl
SET @x = col = col + @x
you cannot be sure what will happen.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Navigation:
[Reply to this message]
|