I created a trigger named UPDATE_MERCHANDISE. The query completed with one error, a simple typo. I fixed the typo and changed the code to ALTER TRIGGER, but now when I try to execute it I receive the error
Invalid object name [dbo].[UPDATE_MERCHANDISE]
Why would it be valid when I created it, but not when I try to alter it? Any and all help/ideas would be appreciated.
Thanks.
USE [CIS31038]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[UPDATE_MERCHANDISE] ON [dbo].[ORDERITEM]
AFTER INSERT, DELETE, UPDATE
AS
BEGIN
DECLARE #ITEMID VARCHAR(2)
DECLARE #TOTAL INT
--INSERT CASE
IF(EXISTS (SELECT * FROM INSERTED) AND NOT EXISTS (SELECT * FROM DELETED))
BEGIN
DECLARE INSERT_CURSOR CURSOR FOR
SELECT ITEMID, SUM(QUANTITY) AS TOTAL
FROM INSERTED
GROUP BY ITEMID
OPEN INSERT_CURSOR
FETCH NEXT FROM INSERT_CURSOR INTO #ITEMID, #TOTAL
WHILE(##FETCH_STATUS = 0)
BEGIN
UPDATE MERCHANDISE
SET QUANTITYONHAND = QUANTITYONHAND - #TOTAL
WHERE ITEMID = #ITEMID
FETCH NEXT FROM INSERT_CURSOR INTO #ITEMID, #TOTAL
END
CLOSE INSERT_CURSOR
DEALLOCATE INSERT_CURSOR
END
--DELETE CASE
IF(EXISTS (SELECT * FROM DELETED) AND NOT EXISTS (SELECT * FROM INSERTED))
BEGIN
DECLARE DELETE_CURSOR CURSOR FOR
SELECT ITEMID, SUM(QUANTITY) AS TOTAL
FROM DELETED
GROUP BY ITEMID
OPEN DELETE_CURSOR
FETCH NEXT FROM DELETE_CURSOR INTO #ITEMID, #TOTAL
WHILE (##FETCH_STATUS = 0)
BEGIN
UPDATE MERCHANDISE
SET QUANTITYONHAND = QUANTITYONHAND + #TOTAL
WHERE ITEMID = #ITEMID
FETCH NEXT FROM DELETE_CURSOR INTO #ITEMID, #TOTAL
END
CLOSE DELETE_CURSOR
DEALLOCATE DELETE_CURSOR
END
--UPDATE CASE
IF(EXISTS (SELECT * FROM INSERTED) AND EXISTS (SELECT * FROM DELETED))
BEGIN
DECLARE UPDATE_CURSOR CURSOR FOR
SELECT I.ITEMID, SUM(I.QUANTITY - D.QUANTITY) AS TOTAL
FROM INSERTED I INNER JOIN DELETED D ON
I.PONUMBER = D.PONUMBER AND I.ITEMID = D.ITEMID
GROUP BY I.ITEMID
OPEN UPDATE_CURSOR
FETCH NEXT FROM UPDATECURSOR INTO #ITEMID, #TOTAL
WHILE (##FETCH_STATUS = 0)
BEGIN
UPDATE MERCHANDISE
SET QUANTITYONHAND = QUANTITYONHAND - #TOTAL
WHERE ITEMID = #ITEMID
FETCH NEXT FROM UPDATE_CURSOR INTO #ITEMID, #TOTAL
END
CLOSE UPDATE_CURSOR
DEALLOCATE UPDATE_CURSOR
END
END
If you had a typo, most likely, the trigger never got created
Try CREATE TRIGGER instead of ALTER TRIGGER
By the way, generally, you remove the trigger and recreate, using something like.
IF Object_id('TRIGGER_NAME') is not null
DROP TRIGGER Trigger Name
GO
CREATE TRIGGER TriggerName
AS
Related
I have table with a myNumber varchar(50) column which stores values with lead zero, like a '0000001111'.
Now I want to replace leading '0000' with '12', like '12001111'.
I tried this statement:
UPDATE myDB.dbo.myTable
SET myNumber = REPLACE(myNumber, '0000', '12')
WHERE myNumber LIKE '0000%'
But this caused an error:
Msg 248, Level 16, State 1, Procedure trplist_for_Inserted_Updated_Deleted Line 80
The conversion of the varchar value "831116399075' overflowed an int column.
Why this error caused if all columns are the varchar?
What should I do?
UPDATED
Sorry guys, the reason of error it is the tables trigger.
Here is triggers logic
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER TRIGGER [dbo].[trplist_for_Inserted_Updated_Deleted]
ON [dbo].[pList]
FOR Insert, Update, Delete
NOT FOR REPLICATION
AS
SET NOCOUNT ON
Declare #Result_check Int
Declare #NameTable nvarchar(30)
set #NameTable='plist'
Declare #FieldName nvarchar(30)
set #FieldName='ChangeTime'
Declare #Columns varbinary(MAX)
set #Columns=COLUMNS_UPDATED()
Execute CheckChangeFields #Columns, #NameTable, #FieldName, #Result_check
if #Result_check = 1
begin
return
end
set #FieldName='DateTimeInArchive'
Execute CheckChangeFields #Columns, #NameTable, #FieldName, #Result_check
if #Result_check = 1
begin
return
end
Declare #stateRecord Int
IF EXISTS(SELECT * FROM inserted)
IF EXISTS(SELECT * FROM deleted)
BEGIN
SET #stateRecord = 1 --Update
--PRINT 'Update'
END
ELSE
BEGIN
--PRINT 'Insert'
SET #stateRecord = 0 --Insert
END
ELSE
BEGIN
--PRINT 'Is DELETE'
IF EXISTS(SELECT * FROM deleted)
BEGIN
SET #stateRecord = 2 --Delete
--PRINT 'DELETE'
END
ELSE
BEGIN
SET #stateRecord = -1
--PRINT 'No DELETE'
END
END
IF #stateRecord = -1
RETURN
declare #id_value int
Declare #status_record int
declare #inn int
declare #Company int
declare #tabnumber varchar(50)
if (#stateRecord in (0,1))
BEGIN
--inserted or updated
--проверка на изменение поля StatusRecord
declare #Result_check_status_record int
if Exists(select * from Deleted where checksum(StatusRecord) In (select Checksum(StatusRecord) from Inserted))
select #Result_check_status_record= 1--одинаковые
else
select #Result_check_status_record= 0--разные
DECLARE cursor_inserted_trpList_Inserted_Updated_Delete_logs CURSOR LOCAL FOR select id, StatusRecord, INN, TabNumber, Company from inserted
OPEN cursor_inserted_trpList_Inserted_Updated_Delete_logs
FETCH NEXT FROM cursor_inserted_trpList_Inserted_Updated_Delete_logs INTO #id_value, #status_record,#inn, #tabnumber, #Company
WHILE ##FETCH_STATUS = 0
BEGIN
if (#inn<>'')
begin
if Exists(select id from plist where (id<> #id_value) and (INN=#inn))
begin
RollBack
RAISERROR('Данный INN уже имеется в базе', 16,2)
CLOSE cursor_inserted_trpList_Inserted_Updated_Delete_logs
return
end
end
if (#tabnumber<>'') and (#tabnumber<>'0')
begin
if #Company = 0
begin
if Exists(select id from plist where (id<> #id_value) and (TabNumber=#tabnumber) and (Company<=0))
begin
RollBack
RAISERROR('Данный TabNumber уже имеется в базе', 16,2)
CLOSE cursor_inserted_trpList_Inserted_Updated_Delete_logs
return
end
end
else
begin
if Exists(select id from plist where (id<> #id_value) and (TabNumber=#tabnumber) and (Company=#Company))
begin
RollBack
RAISERROR('Данный TabNumber уже имеется в базе в данном подразделении', 16,2)
CLOSE cursor_inserted_trpList_Inserted_Updated_Delete_logs
return
end
end
end
if ((#status_record&1)>0)
begin
if (#Result_check_status_record=0)
begin
Execute GustIsRelease #id_value
update guest set IDNoFace=0 where PListID=#id_value
Declare #dmtm datetime
if Exists(select id from plist where (id=#id_value) and (IsNull(DateTimeInArchive, '')=''))
begin
Update plist set DateTimeInArchive=GetDate() where (id=#id_value) and (IsNull(DateTimeInArchive, '')='')
end
end
end
else
begin
if Exists(select id from plist where (id=#id_value) and (IsNull(DateTimeInArchive, 1)<>1))
Update plist set DateTimeInArchive=Null where (id=#id_value) and (IsNull(DateTimeInArchive, 1)<>1)
end
FETCH NEXT FROM cursor_inserted_trpList_Inserted_Updated_Delete_logs INTO #id_value, #status_record,#inn, #tabnumber, #Company
END
CLOSE cursor_inserted_trpList_Inserted_Updated_Delete_logs
END
if (#stateRecord=2)
BEGIN
DECLARE cursor_inserted_trpList_Inserted_Updated_Delete_logs CURSOR LOCAL FOR select id from deleted
OPEN cursor_inserted_trpList_Inserted_Updated_Delete_logs
FETCH NEXT FROM cursor_inserted_trpList_Inserted_Updated_Delete_logs INTO #id_value
WHILE ##FETCH_STATUS = 0
BEGIN
if Exists(select id from pmark where owner=#id_value)
begin
RollBack
RAISERROR('У сотрудника остались активные пароли', 16,2)
CLOSE cursor_inserted_trpList_Inserted_Updated_Delete_logs
return
end
if Exists(select id from guest where IDNoFace=#id_value)
begin
RollBack
RAISERROR('Сотрудник привязан к посетителю', 16,2)
CLOSE cursor_inserted_trpList_Inserted_Updated_Delete_logs
return
end
update guest set IDNoFace=0 where IDNoFace=#id_value
update guest set ReceiveListId=0 where ReceiveListId=#id_value
FETCH NEXT FROM cursor_inserted_trpList_Inserted_Updated_Delete_logs INTO #id_value
END
CLOSE cursor_inserted_trpList_Inserted_Updated_Delete_logs
END
You could use STUFF
UPDATE myDB.dbo.myTable
SET myNumber=stuff(myNumber, 1,4, '12')
WHERE myNumber LIKE '0000%'
Use can use SUBSTRING/STUFF as below:
SUBSTRING:
UPDATE #tblTest
SET Number='12'+SUBSTRING(Number,5,LEN(NUMBER))
WHERE LEFT(Number,4)='0000'
AND LEN(Number)>4
STUFF:
UPDATE #tblTest
SET Number=STUFF(Number, 1,4, '12')
WHERE LEFT(Number,4)='0000'
AND LEN(Number)>4
Use substring function to accomplish the result u want
UPDATE myDB.dbo.myTable
SET Number='12'+SUBSTRING(myNumber,5)
WHERE SUBSTRING(myNumber,1,4)='0000';
What is wrong with this code.
If i type like this
Declare tmp as CURSOR FOR
Select i.ID from Inserted
OPEN tmp
Or if i type
Declare tmp as CURSOR FOR
Select i.ID from Deleted
OPEN tmp
Works like a charm but
Is there any way i can write something like this
if #operation <> 3
set #tmp = 'SELECT i.id FROM inserted i '
else
set #tmp =' SELECT i.id FROM deleted i '
DECLARE tmpUpit CURSOR FOR
#tmp
OPEN tmpUpit
Edit :
CREATE TRIGGER [dbo].[ax_Triger] ON [dbo].[extraTable]
FOR INSERT, UPDATE, DELETE AS
SET NOCOUNT ON;
--Capture the Operation (Inserted, Deleted Or Updated)
DECLARE #operation int
DECLARE #Count AS INT
SET #operation = 1
SELECT #Count = COUNT(*)
FROM DELETED
IF #Count > 0
BEGIN
SET #operation = 3
SELECT #Count = COUNT(*)
FROM INSERTED
IF #Count > 0
SET #operation = 2
END
DECLARE tmpUpit CURSOR FOR
SELECT i.id FROM inserted i
OPEN tmpUpit
FETCH NEXT FROM tmpUpit
into #ID WHILE ##fetch_status = 0
begin If Not exists
(SELECT * FROM mytable
where (Operation=3 OR (Operation=1 AND ID=#ID)) AND Status = 0 AND Tablename ='extraTable')
begin INSERT INTO
mytable ([Field1], [Field2],
[ID], [Tablename], [Operation], [Time12], [Status])
VALUES (#Field1, #Field2, #ID, 'extraTable', #operation,GETDATE(),0)
DELETE FROM mytable
WHERE [Field1]=#Field1 And [Field2]=#Field2 And [ID]=#ID And [Tablename]='extraTable'
AND [Operation] = 4 AND [Status] = 0
End
FETCH NEXT FROM tmpUpit into #ID
End CLOSE tmpUpit DEALLOCATE tmpUpit end
i need to insert the value from one table to another depending about the status Inserted/updated/deleted
This is completely untested since the table structures posted did not match the posted trigger code. This should at least demonstrate how you can rethink about this as set based logic instead of row by agonizing row.
CREATE TRIGGER [dbo].[Trigger212] ON [dbo].[Towns]
FOR INSERT, UPDATE, DELETE AS
BEGIN
SET NOCOUNT ON;
DECLARE #operation int
DECLARE #Variable1 nvarchar(8) = 'Woof'
DECLARE #Variable2 nvarchar(4) = 'Foof'
--Capture the Operation (Inserted, Deleted Or Updated)
IF EXISTS(SELECT * FROM inserted) AND NOT EXISTS (SELECT * FROM deleted)
SET #operation = 1 --Insert
ELSE
IF EXISTS(SELECT * FROM inserted) AND EXISTS (SELECT * FROM deleted)
SET #operation = 2 --update
ELSE
SET #operation = 3 -- DELETE
INSERT Requests
(
Field1
, Field2
, ID
, TableName
, Operation
, TimeU
, Status
)
SELECT 'Woof'
, 'Foof'
, i.ID
, 'Towns'
, #operation
, GETDATE()
, 0
FROM inserted i
LEFT JOIN Requests r on r.ID = i.ID
AND r.Operation = 3
OR (r.Operation = 1 and r.ID = i.ID)
AND r.Status = 0
AND r.TableName = 'Towns'
WHERE r.ID IS NULL
DELETE r
FROM Requests r
JOIN inserted i on i.Field1 = r.Field1
AND i.Field2 = r.Field2
AND i.ID = r.ID
AND i.Operation <> #operation
WHERE r.TableName = 'Towns'
AND r.Status = 0
END
In general I think triggers should be avoided but they have their place. When triggers are appropriate I am generally not a big fan of doing all three operations. Over time it gets really messy because invariably you need to do different logic for the different operations. Splitting them into three triggers makes this eventuality a lot less painful for maintenance.
i have used trigger for recalculation multiple data.
in trigger i have used cursor.in cursor i have used another sp's which is contain 1 more cursor.
so it's very slow for calculation of only 80 rows data. and it's take 20 second to calculate the data. so please give me any suggestion or solution for it quickly.
thanks
here is my trigger
/****** Object: Trigger [dbo].[tr_TransactionJournal_InsteadOfDelete] Script Date: 12/23/2015 3:13:09 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[tr_TransactionJournal_InsteadOfDelete]
ON [dbo].[TransactionJournal]
INSTEAD OF DELETE
AS
SET NOCOUNT ON;
DECLARE
#TxNum INT,
#TxDate DATE
/*
declare #TempDetailTable to figure out which ChartAcctCode & Item needs to be recalculated
*/
DECLARE #TempDetailTable TABLE (
ChartAcctCode NVARCHAR(10),
ItemCode NVARCHAR(10)
)
DECLARE #MyCursor_1 CURSOR
SET #MyCursor_1 = CURSOR FAST_FORWARD
FOR
SELECT TxNum,TxDate FROM DELETED
OPEN #MyCursor_1
FETCH NEXT FROM #MyCursor_1
INTO #TxNum,#TxDate
WHILE ##fetch_status = 0 -- This is executed as long as the previous fetch succeeds.
BEGIN
------------------
BEGIN TRANSACTION
INSERT INTO #TempDetailTable
SELECT DISTINCT tjd.ChartAcctCode, tjd.ItemCode
FROM dbo.TransactionJournalDetail AS tjd
WHERE (tjd.TxNum = #TxNum)-- AND tjd.ItemCode IS NOT NULL
COMMIT TRANSACTION
/*
Actually deleting FROM TxJournal & TxJournalDetail
*/
DELETE FROM TransactionJournal WHERE TxNum=#TxNum
/*
Start Recalculating...
*/
DECLARE #MyChartAcctCode NVARCHAR(10)
DECLARE #MyItemCode NVARCHAR(10)
DECLARE #MyCursor CURSOR
/*
1st Loop to RecalcQAV if Detail has any ChartAcctCode = "AINV"
*/
SET #MyCursor = CURSOR FAST_FORWARD
FOR
SELECT ItemCode FROM #TempDetailTable WHERE ChartAcctCode = 'INV'
OPEN #MyCursor
FETCH NEXT FROM #MyCursor
INTO #MyItemCode
WHILE ##fetch_status = 0
BEGIN
EXEC RecalcQAV #MyItemCode, #TxDate;
FETCH NEXT FROM #MyCursor
INTO #MyItemCode
END
/*
2nd Loop to RecalcAcctBalance if Detail has any ChartAcctCode = "AINV"
*/
SET #MyCursor = CURSOR FAST_FORWARD
FOR
SELECT ChartAcctCode FROM #TempDetailTable
OPEN #MyCursor
FETCH NEXT FROM #MyCursor
INTO #MyChartAcctCode
WHILE ##fetch_status = 0
BEGIN
EXEC RecalcAcctBalance #MyChartAcctCode, #TxDate;
FETCH NEXT FROM #MyCursor
INTO #MyChartAcctCode
END
CLOSE #MyCursor;
DEALLOCATE #MyCursor;
------------------
FETCH NEXT FROM #MyCursor_1
INTO #TxNum,#TxDate
END
CLOSE #MyCursor_1;
DEALLOCATE #MyCursor_1;
ALTER PROCEDURE [dbo].[RecalcAcctBalance]
(
#ChartAcctCode NVARCHAR(10),
#BeginDate DATE
)
AS BEGIN
SET NOCOUNT ON;
DECLARE #LastDate DATE
SELECT #LastDate = MAX(tj.TxDate)
FROM dbo.TransactionJournal AS tj
JOIN dbo.TransactionJournalDetail AS tjd ON tj.TxNum = tjd.TxNum
WHERE tj.TxDate < #BeginDate
AND tjd.ChartAcctCode = #ChartAcctCode
DECLARE #MyTable TABLE (
AutoId INT IDENTITY(1,1) PRIMARY KEY,
TxDate DATE,
TxDetailId INT
)
INSERT INTO #MyTable (TxDate, TxDetailId)
SELECT tj.TxDate, tjd.AutoId
FROM dbo.TransactionJournal AS tj
JOIN dbo.TransactionJournalDetail AS tjd ON tj.TxNum = tjd.TxNum
WHERE tj.TxDate >= ISNULL(#LastDate, #BeginDate)
AND tjd.ChartAcctCode = #ChartAcctCode
ORDER BY tj.TxDate, tj.SourceDocOrder, tjd.AutoId
DECLARE
#LastDateMaxId INT,
#TxDetailId INT,
#LChartAcctBalance MONEY = 0
IF #LastDate IS NOT NULL
BEGIN
SELECT #TxDetailId = TxDetailId
FROM (
SELECT TxDetailId, RowNum = ROW_NUMBER() OVER (ORDER BY AutoId DESC)
FROM #MyTable
WHERE TxDate = #LastDate
) t
WHERE t.RowNum = 1
SELECT #LChartAcctBalance = ISNULL(ChartAcctBalance, 0)
FROM dbo.TransactionJournalDetail
WHERE AutoId = #TxDetailId
END
;WITH cte AS
(
SELECT *, val = #LChartAcctBalance + SUM(Amount) OVER (ORDER BY AutoId)
FROM dbo.TransactionJournalDetail
WHERE AutoId IN (
SELECT TxDetailId
FROM #MyTable
WHERE TxDate >= #BeginDate
)
)
UPDATE cte
SET ChartAcctBalance = val
END
the second sp is too large for refactoring... anyway the main problem - business logic with processing by item...
DECLARE #tag VARCHAR(MAX)
DECLARE #TagID as INT;
DECLARE #ID as INT;
DECLARE tag_cursor CURSOR
FOR
SELECT tagname FROM #temptag
FOR READ ONLY
OPEN tag_cursor
FETCH NEXT FROM tag_cursor INTO #tag
WHILE ##FETCH_STATUS = 0
BEGIN
IF EXISTS (SELECT TOP 1 * FROM Tag WHERE TagName=#tag)
BEGIN
print 1;
END
print 2;
/* INSERT INTO Tag
SELECT #tag FROM #temptag
SELECT #TagID = SCOPE_IDENTITY();
print #TagID*/
FETCH NEXT FROM tag_cursor INTO #tag
END
CLOSE tag_cursor
DEALLOCATE tag_cursor
In my stored procedure I am searching for a value in the table. If the value already exists then I should not insert value.
so I have written
IF EXISTS (SELECT TOP 1 * FROM Tag WHERE TagName=#tag)
BEGIN
print 1;
END
print 2;
/* INSERT INTO Tag
SELECT #tag FROM #temptag
SELECT #TagID = SCOPE_IDENTITY();
print #TagID*/
FETCH NEXT FROM tag_cursor INTO #tag
END
Problem: When I run it both values print1 and print 2 are getting printed
Can someone help me in fixing the error
Perhaps you meant to have an ELSE block?
IF EXISTS (SELECT TOP 1 * FROM Tag WHERE TagName=#tag)
BEGIN
print 1;
END
ELSE
BEGIN
print 2;
/* INSERT INTO Tag
SELECT #tag FROM #temptag
SELECT #TagID = SCOPE_IDENTITY();
print #TagID*/
END
I want to use cursor to delete record from table. How can I do it?
I use MSSQL 2008 Express this code does not delete anything from #temp. I also tried where current of cursor_name did not work.
Here is my sample code:
use AdventureWorks
drop table #temp
select * into #temp from HumanResources.Employee;
declare #eid as int;
declare #nid as varchar(15);
DECLARE Employee_Cursor CURSOR FOR
SELECT A.EmployeeID, A.NationalIDNumber FROM #temp AS A
OPEN Employee_Cursor;
FETCH NEXT FROM Employee_Cursor INTO #eid , #nid ;
WHILE ##FETCH_STATUS = 0
BEGIN
IF (#eid > 10)
BEGIN
delete from #temp where #temp.EmployeeID = #eid;
END
FETCH NEXT FROM Employee_Cursor;
END;
CLOSE Employee_Cursor;
DEALLOCATE Employee_Cursor;
GO
select * from #temp
thanks in advance
use AdventureWorks
select * into #temp from HumanResources.Employee;
declare #eid as int;
declare #nid as varchar(15);
DECLARE Employee_Cursor CURSOR FOR
SELECT A.EmployeeID, A.NationalIDNumber FROM #temp AS A
OPEN Employee_Cursor;
FETCH NEXT FROM Employee_Cursor INTO #eid , #nid ;
WHILE ##FETCH_STATUS = 0
BEGIN
IF (#eid > 10)
BEGIN
delete from #temp where current of Employee_Cursor
END
FETCH NEXT FROM Employee_Cursor INTO #eid , #nid ;
END;
CLOSE Employee_Cursor;
DEALLOCATE Employee_Cursor;
select * from #temp
drop table #temp
this works for me
There is a much simpler answer - use this command:
delete from HumanResources.Employee where current of Employee_Cursor
It's called 'Positioned delete' and described at MSDN.
Could you please try in below ways, thanks for your time.
You have fetched data from cursor but didn't push into your variables missed in WHILE loop, please have a look on below code, thanks.
drop table #temp
select * into #temp from Employee;
declare #eid as int;
declare #nid as varchar(15);
DECLARE Employee_Cursor CURSOR FOR
SELECT A.EmployeeID, A.NationalIDNumber FROM #temp AS A
OPEN Employee_Cursor;
FETCH NEXT FROM Employee_Cursor INTO #eid , #nid ;
WHILE ##FETCH_STATUS = 0
BEGIN
IF (#eid > 10)
BEGIN
delete from #temp where #temp.EmployeeID = #eid;
END
FETCH NEXT FROM Employee_Cursor INTO #eid , #nid ;
END;
CLOSE Employee_Cursor;
DEALLOCATE Employee_Cursor;
GO
select * from #temp
Update:
I've changes in 2nd FETCH statement, just have added below highlighted part, thanks
FETCH NEXT FROM Employee_Cursor INTO #eid , #nid ;