I have created a procedure which start by fecthing data from DB-X and put in into the temporary memory. what im trying to do now is to take data from temporary memory insert/update DB-Y.
But now I get this ERROR Msg 512, Level 16, State 1, Line 33
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
HERE IS MY PROCEDURE
DECLARE @MineID int,
@MineName varchar(80),
@MineDescription [varchar](80) ,
@MineLocation varchar(80),
@Country varchar(80),
@Northing float,
@Easting float,
@Elevation float,
@Latitude float ,
@Longitude float,
@MineLogo varbinary(max)
DECLARE MYCURSOR CURSOR
FOR SELECT * FROM [TLC].[DBO].[MINE]
OPEN MYCURSOR
FETCH NEXT FROM MYCURSOR INTO
@MineID,
@MineName ,
@MineDescription ,
@MineLocation ,
@Country ,
@Northing ,
@Easting ,
@Elevation ,
@Latitude,
@Longitude,
@MineLogo
WHILE @@FETCH_STATUS = 0
BEGIN
IF @MineID =(select MineID from [TEST].[dbo].[MINE1])
SET IDENTITY_INSERT [TEST].[dbo].[MINE1] ON
BEGIN UPDATE [TEST].[dbo].[MINE1]
SET MineName = @MineName
,MineDescription = @MineDescription
,MineLocation = @MineLocation
,Country =@Country
,Northing = @Northing
,Easting = @Easting
,Elevation = @Elevation
,Latitude = @Latitude
,Longitude = @Longitude
,MineLogo =@MineLogo
where MineId = @MineID
END
IF @MineID <> (select MineID from [TEST].[dbo].[MINE1])
SET IDENTITY_INSERT [TEST].[dbo].[MINE1] ON
INSERT INTO [TEST].[dbo].[MINE1]
(MineID
,MineName
,MineDescription
,MineLocation
,Country
,Northing
,Easting
,Elevation
,Latitude
,Longitude
,MineLogo )
VALUES (
@MineID
,@MineName
,@MineDescription
,@MineLocation
,@Country
,@Northing
,@Easting
,@Elevation
,@Latitude
,@Longitude
,@MineLogo)
FETCH NEXT FROM MYCURSOR INTO
@MineID,
@MineName ,
@MineDescription ,
@MineLocation ,
@Country ,
@Northing ,
@Easting ,
@Elevation ,
@Latitude,
@Longitude,
@MineLogo
END
SET IDENTITY_INSERT [TEST].[dbo].[MINE1] OFF
SET IDENTITY_INSERT [TEST].[dbo].[MINE1] OFF
CLOSE MYCURSOR
DEALLOCATE MYCURSOR