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
 General SQL Server Forums
 New to SQL Server Programming
 INSERT STATEMENT FAILING WITH MULTIPLE VALUES

Author  Topic 

Chris_Kelley
Posting Yak Master

114 Posts

Posted - 2014-08-19 : 12:19:17
c

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-08-19 : 12:43:20
You are trying to add the same MAX+1 value multiple times as it's only computed once for your one insert. If you need different values, then use insert/select multiple times.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 2014-08-19 : 12:43:55
You may want to re-think your design.

WITH NewRows
AS
(
SELECT *
FROM
(
VALUES (1,'CLIENT_NAME','C',0,0)
,(2,'PORT_ID','C',0,0)
,(3,'DOA1','C',0,0)
,(4,'STATUS_DATE','C',0,0)
,(5,'CUST_TYP','C',0,0)
,(6,'LOAN_CD_TYP','C',0,0)
,(7,'BAL','C',0,0)
,(8,'DATE_LPAY','C',0,0)
,(9,'AMT_LPAY','C',0,0)
,(10,'CHRG_OFF_D','C',0,0)
,(11,'CHRG_OFF_A','C',0,0)
,(12,'SETT_AUTH','C',0,0)
,(13,'NAME','C',0,0)
,(14,'D_SUFFIX','C',0,0)
,(15,'PATIENT_NM','C',0,0)
,(16,'D_EMP_STREET','C',0,0)
,(17,'D_EMP_STREET2','C',0,0)
,(18,'D_EMP_CITY','C',0,0)
,(19,'D_EMP_STATE','C',0,0)
,(20,'D_EMP_ZIP','C',0,0)
,(21,'ORIG_CRED','C',0,0)
,(22,'FRST_DT_DELQ','C',0,0)
,(23,'AGENCY_COMM','C',0,0)
,(24,'PALL_ACCTNO','C',0,0)
,(25,'ORIG_ACCTNO','C',0,0)
,(26,'D_PHYSICIAN','C',0,0)
,(27,'D_EMP','C',0,0)
,(28,'FACILITY_NM','C',0,0)
,(29,'DIAG_CD','C',0,0)
) d (SD_KEY, SD_TYPE, EDIT_SECURITY, MULTI_RECORDS, OtherCol)
)
,MaxVal(SD_KEYMax)
AS
(
SELECT MAX(SD_KEY)
FROM SDMAST WITH (UPDLOCK, SERIALIZABLE)
)
INSERT INTO SDMAST
SELECT SD_KeyMax + SD_KEY, SD_TYPE, EDIT_SECURITY, MULTI_RECORDS, OtherCol
FROM NewRows
CROSS JOIN MaxVal;
Go to Top of Page

Chris_Kelley
Posting Yak Master

114 Posts

Posted - 2014-08-19 : 12:51:28
c
Go to Top of Page

Ifor
Aged Yak Warrior

700 Posts

Posted - 2014-08-19 : 13:08:33
Umm...
The coding is a kludge as the underlying design looks awful.
Go to Top of Page
   

- Advertisement -