Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
193 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 1000 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

Technology Partners: 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 PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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