SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 INSERT STATEMENT FAILING WITH MULTIPLE VALUES
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Chris_Kelley
Posting Yak Master

114 Posts

Posted - 08/19/2014 :  12:19:17  Show Profile  Reply with Quote
c

Edited by - Chris_Kelley on 11/11/2014 19:32:37

tkizer
Almighty SQL Goddess

USA
37291 Posts

Posted - 08/19/2014 :  12:43:20  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

615 Posts

Posted - 08/19/2014 :  12:43:55  Show Profile  Reply with Quote
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 - 08/19/2014 :  12:51:28  Show Profile  Reply with Quote
c

Edited by - Chris_Kelley on 11/11/2014 19:32:46
Go to Top of Page

Ifor
Aged Yak Warrior

615 Posts

Posted - 08/19/2014 :  13:08:33  Show Profile  Reply with Quote
Umm...
The coding is a kludge as the underlying design looks awful.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000