how so I get the uniqueidentifier after insert in SQLEXPRESS?

Posted on 2009-12-17
Last Modified: 2013-11-25
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!
Question by:Agent909
    LVL 10

    Accepted Solution

    DECLARE @GUID uniqueidentifier
    INSERT Item VALUES (@GUID,'Yak Hoof')

    and return the value of @GUID as output parameter
    LVL 1

    Author Comment

    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.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
    What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now