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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get row count of current SQL query 8 64
SQL Backup skipping a few tables 7 58
Query to Add Late Tolerance 10 82
Addition to SQL for dynamic fields 6 56
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 …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

762 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