• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

how so I get the uniqueidentifier after insert in SQLEXPRESS?

I need to create a batch number for entering a set of records.  I have a batch table that stores the unique batch number and other information about the batch.  When the user clicks "New" to create a new batch, I use the Insert command to add the record.  But then I need the uniqueidentifier that was created for the batch number.  What is the SQL syntax for this?

Thanks in advance!
0
Agent909
Asked:
Agent909
1 Solution
 
anvCommented:
DECLARE @GUID uniqueidentifier
SET @GUID = NEWID()
INSERT Item VALUES (@GUID,'Yak Hoof')

and return the value of @GUID as output parameter
0
 
Agent909Author Commented:
This isn't going to work.  I was thinking that a primary key, as in MS Access, can be an auto-generated number that makes each record unique in the table.  I guess the uniqueidentifier does that, but it's much too large for my purposes.  The situation I have is where I have a Batch table that needs a primary key to identify the batch uniquely.  For example, I'd like to add a new batch record, and have the first batch number be '1', the second batch be number '2', etc.  Is this a number I will have to keep track of and increment by one for each new batch myself?  There must be a way that SQLEXPRESS can do this for me.  Do you have any suggestions?  Thanks, and sorry I didn't understand more about what I was asking in the first place.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now