Hello Sir,
I am facing a problem in migrating a cursor declarartion from Oracle to
MSSQL
This in Oracle
cursor cursSku (prId IN NUMBER) is
select * from sku where p_id = prId;
Has to be migrated to MSSQL
Thanks
Nivedita
Printable View
Hello Sir,
I am facing a problem in migrating a cursor declarartion from Oracle to
MSSQL
This in Oracle
cursor cursSku (prId IN NUMBER) is
select * from sku where p_id = prId;
Has to be migrated to MSSQL
Thanks
Nivedita
I don't think that Transact SQL has parameterized CURSORS like PL/SQL. Someone correct me if I'm wrong.
Here's how to create the cursor(example assuming you're not in a sp):
--DECLARE @prId variable
DECLARE @prId int
--SET @prId TO A VALUE
SET @prId = 4
--DECLARE AND DEFINE THE CURSOR
DECLARE curSku CURSOR FOR
SELECT *
FROM sku
WHERE p_id = @prId
OPEN curSku --OPEN CURSOR
/* FETCH ...
Do your cursor
processing stuff
*/
CLOSE curSku --CLOSE CURSOR
--REMOVE CURSOR REFERENCE
DEALLOCATE Employee_Cursor
May want to check out Cursors in Books Online for more help.
Good Luck!!!
WiLeYjAcK
:cool:
This is the cursor code I use:
DECLARE @oldId int
DECLARE Users_cursor CURSOR FOR SELECT field1, field2
FROM yourTable
OPEN Users_cursor
FETCH NEXT FROM Users_cursor INTO @oldId
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS <> -2)
BEGIN
-----do what you have to do
END
FETCH NEXT FROM Users_cursor INTO @oldId
END
DEALLOCATE Users_cursor
Hope this helps