Solved

I am looking for the proper syntax using a SProc to insert rows into a table which contains multiple fields (not primary key) with a GUID datatype.

Posted on 2009-04-14
5
192 Views
Last Modified: 2012-05-06
The GUID columns contain the foreign key references to related tables.
MS SQL Server 2005
0
Comment
Question by:plord1234
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24142344
can you please clarify the table design and the exact problem?
0
 

Author Comment

by:plord1234
ID: 24142493
DECLARE
@Id        uniqueidentifier,
@prod_id   uniqueidentifier,
@attr_id   uniqueidentifier,
@sort      INT

SET @Id = NEWID()
SET @prod_id = Guid('3584e5ed-23a0-4aaa-86ce-9be600ac96a4')
SET @attr_id = Guid('d1b3efd9-f336-4694-81c9-9bea0105c1df')

EXEC dbo.AS_C_ProductsAttributes_Insert
     @id          = Id    ,
     @prod_id     = @prod_id   ,
     @attr_id     = @attr_id   ,
     @sort     =    2  
     
GO


Below is the Procedure I created.

CREATE PROCEDURE dbo.AS_C_ProductsAttributes_Insert
             @id                  uniqueidentifier               ,
             @prod_id             uniqueidentifier               ,
             @attr_id             uniqueidentifier               ,
             @sort                INT                
AS
BEGIN
     SET NOCOUNT ON  

     INSERT INTO dbo.AS_C_ProductAttribute
          (
            Id                            ,
            ProductId                     ,
            AttributeId                   ,
            SortOrder                                    
          )
     VALUES
          (
            @id                         ,
            @prod_id                    ,
            @attr_id                    ,
            @sort                    
            )
END

GO

0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 24142779
so , what is the problem?
DECLARE
@Id        uniqueidentifier,
@prod_id   uniqueidentifier,
@attr_id   uniqueidentifier,
@sort      INT
 
SET @Id = NEWID()
SET @prod_id = cast('3584e5ed-23a0-4aaa-86ce-9be600ac96a4' as uniqueidentifier)
SET @attr_id = cast('d1b3efd9-f336-4694-81c9-9bea0105c1df' as uniqueidentifier)
 
EXEC dbo.AS_C_ProductsAttributes_Insert
     @id          = Id    ,
     @prod_id     = @prod_id   ,
     @attr_id     = @attr_id   ,
     @sort     =    2  

Open in new window

0
 

Author Comment

by:plord1234
ID: 24142942
DECLARE
@Id        uniqueidentifier,
@prod_id   uniqueidentifier,
@attr_id   uniqueidentifier,
@sort      INT
 
SET @Id = NEWID()
SET @prod_id = cast('3584e5ed-23a0-4aaa-86ce-9be600ac96a4' as uniqueidentifier)
SET @attr_id = cast('d1b3efd9-f336-4694-81c9-9bea0105c1df' as uniqueidentifier)
 
EXEC dbo.AS_C_ProductsAttributes_Insert
     @id          = @Id    ,
     @prod_id     = @prod_id   ,
     @attr_id     = @attr_id   ,
     @sort     =    2  
 
0
 

Accepted Solution

by:
plord1234 earned 0 total points
ID: 24142959
AngelIII,

Minor correction just in case someone else uses this solution.

EXEC dbo.AS_C_ProductsAttributes_Insert
     @id          = @Id    ,


Thanks for the help!
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

617 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