Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5972225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:37:41+00:00 2026-05-22T20:37:41+00:00

I have this stored procedure which stores information in several tables and one of

  • 0

I have this stored procedure which stores information in several tables and one of the key variables is that I can feed the procedure with a guid value to bind these tables.

It goes something like

USE [MyDatabase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[my_createCompany]
    @CompanyName nvarchar(255),
    @CompanyDescription nvarchar(255),
    @ParentGuid uniqueidentifier
AS
    BEGIN

        DECLARE @CompanyGuid uniqueidentifier
        SET @CompanyGuid = NEWID()

        SET NOCOUNT ON
    Insert into [dbo].[tblPROCompany]
    (
        [CompanyGuid],
        [CompanyName],
        [CompanyDescription],
        [ParentGuid]
    )
    VALUES
    (
        @CompanyGuid,
        @CompanyName,
        @CompanyDescription,
        @ParentGuid
    )
END

It looks right, but when assigning a GUID to the variable @ParentGuid the procedure fails. When I look at the output it something like this

USE [MyDatabase]
GO    
DECLARE @return_value int    
EXEC    @return_value = [dbo].[my_createCompany]
        @CompanyName = N'Asd',
        @CompanyDescription = NULL,
        @ParentGuid = 4864DE55-60FB-4A69-814F-428B0178F4BB

SELECT  'Return Value' = @return_value

GO

And the error of course
Msg 102, Level 15, State 1, Line 7
Incorrect syntax near ‘DE55’.

So it doesn’t encapsulate the @ParentGuid as it should. For now I’ve made a workaround declaring the @ParentGuid as a varchar

@ParentGuid varchar(37), --uniqueidentifier

and the converting it to what the database wants before the insert

if @ParentGuid is not null
BEGIN
    DECLARE @ParentGuidConverted uniqueidentifier
    SET @ParentGuidConverted = convert(uniqueidentifier, @ParentGuid)
END

Is there a better way of doing this?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:37:41+00:00Added an answer on May 22, 2026 at 8:37 pm

    That’s only the (partially) broken behaviour when executing the stored procedure using the SSMS wizard. When actually calling it from client code, most data access libraries allow you to pass parameters using the appropriate types (e.g. as a Guid from .Net code), and the data access library will ensure that it’s passed across appropriately.

    If writing it directly into a query window, surround the value by single quotes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that logs some data, how can I call this
I have a crystal report that gets its data from one stored procedure, this
I have a stored procedure which selects various information about suppliers. One of these
Let's say that I have a form which runs a stored procedure. This stored
I have this stored procedure, which is mapped in an Entity Framework 4.1 object.
I have this stored procedure that I want to use for my SAP crystal
I have a stored procedure that has this line: SET @SQL = 'SELECT path,title,tags
I have a mysql stored procedure from this ( google book ), and one
I have a stored procedure that updates a table using linq, eg: (this is
I have written a SQL Server stored procedure that includes a DateTime parameter. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.