Just nu i M3-nätverket
Jump to content

Hjälp! INSERT statement conflicted with COLUMN CHECK constraint 'CK_TAddresses_PhoneNr'


heatsinkfan

Recommended Posts

heatsinkfan

DECLARE @SourceID INT
SET @SourceID = 344

SELECT GETDATE() AS starttid

DECLARE @Pid SMALLINT
DECLARE @Cid SMALLINT
SET @Pid = 160
SET @Cid = 160

DECLARE @CustomerID int
DECLARE @AddressSerial tinyint
DECLARE @MLAST varchar(50)
DECLARE @MFIRST varchar(50)
DECLARE @PhoneNr varchar(30)
DECLARE @AD1 varchar(100)
DECLARE @POST varchar(10)
DECLARE @CITY varchar(30)
DECLARE @CED1 varchar(50)
DECLARE @CED2 varchar(50)
DECLARE @CED3 varchar(50)
DECLARE @CED4 varchar(50)
DECLARE @CED5 varchar(50)
DECLARE @CED6 varchar(50)
DECLARE @AED1 varchar(50)
DECLARE @AED2 varchar(50)
DECLARE @AED3 varchar(50)
DECLARE @AED4 varchar(50)
DECLARE @AED5 varchar(50)
DECLARE @AED6 varchar(50)
DECLARE @AED7 varchar(50)
DECLARE @AED8 varchar(50)
DECLARE @AED9 varchar(50)
DECLARE @AED10 varchar(50)
DECLARE @FaxNr varchar(30)
DECLARE @EMail varchar(100)

BEGIN TRANSACTION
DECLARE Curse CURSOR FOR

SELECT FirmaNamn, KontaktPerson, Address, PostCode, PostOffice, GateAdresse, PhoneNr, Dialer
FROM DTemp.dbo.KenBed
WHERE Dialer = 'A'
ORDER BY NEWID()

OPEN Curse
FETCH NEXT FROM Curse INTO @MFIRST,@MLAST,@AD1,@POST,@CITY,@PhoneNr,@CED1,@CED2
WHILE @@FETCH_STATUS = 0 AND @@ERROR = 0
BEGIN
INSERT INTO Dialer1_2_A.dbo.TCustomers (AddressNr,State,PrevState,ProjectID,CampaignID,Priority,[Name],[Name2],SourceID, ED1,ED2,ED3)
VALUES (1,0,0,@Pid,@Cid,0,ISNULL(@MFIRST,''),ISNULL(@MLAST,''), @SourceID,ISNULL(@CED1,''),ISNULL(@CED2,''),ISNULL(@CED3,''))
SELECT @CustomerID = @@IDENTITY

SELECT @AddressSerial = ISNULL(MAX(Serial),0) + 1 FROM Dialer1_2_A.dbo.TAddresses WHERE CustomerID = @CustomerID

INSERT INTO Dialer1_2_A.dbo.TAddresses (Serial,CustomerID,PostAddress,PostCode,PostOffice,PhoneNr)
VALUES (@AddressSerial,@CustomerID,ISNULL(@AD1,''),ISNULL(@POST,''),ISNULL(@CITY,''),ISNULL(@PhoneNr,''))

IF @@ERROR <> 0 
BEGIN
	PRINT 'Error in TAddresses!'
	BREAK
END

FETCH NEXT FROM Curse INTO @MFIRST,@MLAST,@AD1,@POST,@CITY,@PhoneNr,@CED1,@CED2
END
CLOSE Curse
DEALLOCATE Curse
COMMIT TRANSACTION
SET NOCOUNT OFF

GO
SELECT GETDATE() AS sluttid

 

[inlägget ändrat 2009-03-10 20:36:00 av Mr Andersson]

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...