Board index » delphi » copying datasets

copying datasets


2004-01-21 07:32:54 PM
delphi85
Hi there,
I need to duplicate entries of a table in the same table again apart from
the primary key.
What I need is a simple sql statement that does the job. Something like:
CREATE PROCEDURE COPY_UMFTYP @UMFRAGETYP varchar(50), @UMFRAGETYPID int
AS
DECLARE @MAXNR int
SET @MAXNR = (SELECT MAX(TYP_ID)+1 FROM T_TYP)
IF @MAXNR IS NULL SET @MAXNR = 1
INSERT INTO T_TYP (TYP_TYPNAME, TYP_ID) VALUES (@UMFRAGETYP, @MAXNR)
INSERT INTO T_ATYP (ATYP_TYP_ID, ATYP_NR, ATYP_AUSSAGE, ATYP_FAKT_ID,
ATYP_NEGATIV)
VALUES (@MAXNR, (SELECT ATYP_NR, ATYP_AUSSAGE, ATYP_FAKT_ID, ATYP_NEGATIV
FROM T_ATYP WHERE ATYP_TYP_ID = @UMFRAGETYPID))
Unfortunately, this statement does not work, but what do I have to change to
get it running?
Thanks,
Pascal
 
 

Re:copying datasets

Pascal Schmidt-Volkmar writes:
Quote

INSERT INTO T_ATYP (ATYP_TYP_ID, ATYP_NR, ATYP_AUSSAGE, ATYP_FAKT_ID,
ATYP_NEGATIV)
VALUES (@MAXNR, (SELECT ATYP_NR, ATYP_AUSSAGE, ATYP_FAKT_ID,
ATYP_NEGATIV FROM T_ATYP WHERE ATYP_TYP_ID = @UMFRAGETYPID))

Unfortunately, this statement does not work, but what do I have to
change to get it running?
I'm not expert with MS SQL but I think the correct syntax would be
INSERT INTO T_ATYP (ATYP_TYP_ID, ATYP_NR, ATYP_AUSSAGE, ATYP_FAKT_ID,
ATYP_NEGATIV)
SELECT @MAXNR, ATYP_NR, ATYP_AUSSAGE, ATYP_FAKT_ID,
ATYP_NEGATIV FROM T_ATYP WHERE ATYP_TYP_ID = @UMFRAGETYPID
I.e. replace the VALUES clause with the SELECT rather than trying to use
both.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: www.logicfundamentals.com/RADBooks.html
"It is error alone which needs the support of government. Truth can
stand by itself." - Thomas Jefferson