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
191 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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