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
180 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
  • 3
  • 2
5 Comments
 
LVL 142

Expert Comment

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

Author Comment

by:plord1234
Comment Utility
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 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

772 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

11 Experts available now in Live!

Get 1:1 Help Now