Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #84 > unrolled thread

Getting a Batch Number

Started byGene Wirchenko <genew@ocis.net>
First post2011-03-31 14:19 -0700
Last post2011-03-31 15:08 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.databases.ms-sqlserver


Contents

  Getting a Batch Number Gene Wirchenko <genew@ocis.net> - 2011-03-31 14:19 -0700
    Re: Getting a Batch Number Erland Sommarskog <esquel@sommarskog.se> - 2011-03-31 23:46 +0200
      Re: Getting a Batch Number Gene Wirchenko <genew@ocis.net> - 2011-03-31 15:08 -0700

#84 — Getting a Batch Number

FromGene Wirchenko <genew@ocis.net>
Date2011-03-31 14:19 -0700
SubjectGetting a Batch Number
Message-ID<4ar9p6t864rknp0k2b6coc2ra684951c1l@4ax.com>
Dear SQLers:

     I now want to put together a simple database.  I thought that I
would try something that modelled the way I do banking.  I can have
multiple set-asides in one bank account.  I might write a cheque off
one account that is to put money in more than one set-aside.  (Or I
might transfer; it amounts to the same.)  For example:

          cheque for $500 from Income account to Savings Account
split:
               Reserves $200, Income Tax Set-Aside $300.

     This gives me a transaction batch of:

          insert into Batches 'Sample Batch'
           (with an id column value automatically generated)

          insert into Transactions '20110331','Income',-500
          insert into Transactions '20110331','Reserves',200
          insert into Transactions '20110331','Income Tax S/A',200

     How do I get the batch number from Batches to use in the
Transactions inserts?

Sincerely,

Gene Wirchenko

[toc] | [next] | [standalone]


#85

FromErland Sommarskog <esquel@sommarskog.se>
Date2011-03-31 23:46 +0200
Message-ID<Xns9EB9F1D1AC66CYazorman@127.0.0.1>
In reply to#84
Gene Wirchenko (genew@ocis.net) writes:
>      I now want to put together a simple database.  I thought that I
> would try something that modelled the way I do banking.  I can have
> multiple set-asides in one bank account.  I might write a cheque off
> one account that is to put money in more than one set-aside.  (Or I
> might transfer; it amounts to the same.)  For example:
> 
>           cheque for $500 from Income account to Savings Account
> split:
>                Reserves $200, Income Tax Set-Aside $300.
> 
>      This gives me a transaction batch of:
> 
>           insert into Batches 'Sample Batch'
>            (with an id column value automatically generated)
> 
>           insert into Transactions '20110331','Income',-500
>           insert into Transactions '20110331','Reserves',200
>           insert into Transactions '20110331','Income Tax S/A',200
> 
>      How do I get the batch number from Batches to use in the
> Transactions inserts?
 
scope_identity()


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

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

[toc] | [prev] | [next] | [standalone]


#86

FromGene Wirchenko <genew@ocis.net>
Date2011-03-31 15:08 -0700
Message-ID<5pu9p69biiu5nstnn1tl2fvi038u4btc76@4ax.com>
In reply to#85
On Thu, 31 Mar 2011 23:46:18 +0200, Erland Sommarskog
<esquel@sommarskog.se> wrote:

>Gene Wirchenko (genew@ocis.net) writes:

[snip]

>>      How do I get the batch number from Batches to use in the
>> Transactions inserts?
> 
>scope_identity()

     Thank you for the magic word.  I am now working my way through a
tutorial I found.

Sincerely,

Gene Wirchenko

[toc] | [prev] | [standalone]


Back to top | Article view | comp.databases.ms-sqlserver


csiph-web