Axapta Code solutions Education and Entertainments Earn Money its Real Experience of knowledge Imortant Weblink collections Fun and Entertainment God thoughts Get Ways to Invest your money Products overview and details
How to use cursor in stored procedure in MS SQL
DECLARE @ testcols1 AS varchar(30)
DECLARE @ testcols2 AS varchar(30)
DECLARE c_Cursor CURSOR FOR SELECT Col1, Col2 from Customer
OPEN c_ Cursor
FETCH NEXT FROM c_ Cursor INTO @ testcols1, @ testcols2
WHILE @@FETCH_STATUS=0
BEGIN
Exec ('select ' + @ testcols1 + ' , ' + @vcol2 + ' from CustE)
FETCH NEXT FROM c_ Cursor INTO @ testcols1, @ testcols2
END
CLOSE c_ Cursor
DEALLOCATE c_ Cursor
How to use cursor in stored procedure in MS SQL
DECLARE @ testcols1 AS varchar(30)
DECLARE @ testcols2 AS varchar(30)
DECLARE c_Cursor CURSOR FOR SELECT Col1, Col2 from Customer
OPEN c_ Cursor
FETCH NEXT FROM c_ Cursor INTO @ testcols1, @ testcols2
WHILE @@FETCH_STATUS=0
BEGIN
Exec ('select ' + @ testcols1 + ' , ' + @vcol2 + ' from CustE)
FETCH NEXT FROM c_ Cursor INTO @ testcols1, @ testcols2
END
CLOSE c_ Cursor
DEALLOCATE c_ Cursor
0 comments:
Post a Comment