Assigning Select NewID() to variable in SQL

Posted on 2007-10-03
Last Modified: 2012-06-21
Dear Experts,

I'm trying to write a stored procedure and require a GUID. I know that SELECT NewID() will return a GUID, but how can I assign this value to a variable within my stored procedure?


Question by:nkewney
    LVL 142

    Accepted Solution

    declare @nid uniqueidentifier
    set @nid = NEWID()

    LVL 1

    Author Comment

    Simple as that - thanks !

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
    Viewers will learn how the fundamental information of how to create a table.

    779 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

    10 Experts available now in Live!

    Get 1:1 Help Now