I have a table (say, Table1) defined as:
Column Type
------ ---------------
ID indentity int(Primary key)
nameData varchar(32)
In a stored procedure I want to query for a record with a
particular value for nameData. If it is there, I want to
retrieve its ID. If not, insert a new record.
The procedure is defined as:
ALTER PROCEDURE up_CheckName
AS
DECLARE table_cursor CURSOR FOR
SELECT Table1.ID FROM dbo.Table1
-- Look up name in Table1 or insert new name
OPEN table_cursor
FETCH NEXT FROM table_cursor
IF Cursor_Status('local', 'table_cursor') <= 0
BEGIN
INSERT INTO dbo.Table1 (Table1.nameData)
END
CLOSE table_cursor
In the query analyzer de* I execute the procedure
However, the new record is not present in Table1. What is
going on? Why? How do I fix it?