Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 .NET Inside SQL Server (2005)
 How from one table to store data in another table

Author  Topic 

programer
Posting Yak Master

221 Posts

Posted - 2010-08-02 : 12:56:55
Hi,

My code:

ALTER PROCEDURE dbo.Select_Customer
(
@UserId varchar(100),
@PaymentType varchar(100),
@PaymentId varchar(100),
@AttributeName varchar(100),
@Value varchar(100)
)
AS
BEGIN

INSERT INTO dbo.tbl_Payment
(UserId,
PaymentType )
VALUES (@UserId,
@PaymentType);

SET IDENTITY_INSERT tbl_Payment ON;

INSERT INTO dbo.tbl_PaymentDetails
(PaymentId,
AttributeName,
Value )
VALUES (@PaymentId(),
@AttributeName,
@Value);


END;



How the information in Table tbl_Payment - COLUMN: UserId (primary key) save to data another table tbl_PaymentDetails - PaymentId column (varchar).


Thanks.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-08-02 : 13:03:00
look for SCOPE_IDENTITY()



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

programer
Posting Yak Master

221 Posts

Posted - 2010-08-02 : 13:06:19
quote:
Originally posted by webfred

look for SCOPE_IDENTITY()



No, you're never too old to Yak'n'Roll if you're too young to die.



Yes, but this is not work:
ALTER PROCEDURE dbo.Select_Customer
(
@UserId varchar(100),
@PaymentType varchar(100),
@PaymentId varchar(100),
@AttributeName varchar(100),
@Value varchar(100)
)
AS
BEGIN

INSERT INTO dbo.tbl_Payment
(UserId,
PaymentType )
VALUES (@UserId,
@PaymentType);

SET IDENTITY_INSERT tbl_PaymentDetails ON;

INSERT INTO dbo.tbl_PaymentDetails
(PaymentId,
AttributeName,
Value )
VALUES (SCOPE_IDENTITY(),
@AttributeName,
@Value);
END;


Please help!
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-08-02 : 13:12:19
Any error message?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2010-08-02 : 14:31:50
Could you post the DDL of dbo.tbl_Payment and dbo.tbl_PaymentDetails. ?
I need to know whether you have a column on dbo.tbl_PaymentDetails that has an identity property,



Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

programer
Posting Yak Master

221 Posts

Posted - 2010-08-02 : 15:50:06
quote:
Originally posted by jackv

Could you post the DDL of dbo.tbl_Payment and dbo.tbl_PaymentDetails. ?
I need to know whether you have a column on dbo.tbl_PaymentDetails that has an identity property,



Jack Vamvas
--------------------
http://www.sqlserver-dba.com




Now it works!

My code:

INSERT INTO dbo.tbl_Payment
(UserId,
PaymentType )
VALUES (@UserId,
@PaymentType);

SET IDENTITY_INSERT tbl_Payment ON;

INSERT INTO dbo.tbl_PaymentDetails
(PaymentId,
AttributeName,
Value )
VALUES (SCOPE_IDENTITY(),
@AttributeName,
@Value);
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-02 : 16:04:43
Why are you turning on IDENTITY_INSERT for tbl_Payment? It doesn't make sense. I don't think you understand what that line of code is doing.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -