SQL Server 2016 Hosting – Example of SQL Cursor with Syntax?
|In this article, we have a tendency to take an Example of sql cursor. we think about a table in my sql databse named is my_testing. the data base table name is Login_table. currently we wish to create a cursor named my_cursor. and wish to search out all recored in login_table. cursor could be a database object utilized by applications to manipulate data in a set on a row-by-row basis, it’s like recordset in ASP and Visual Basic.
Now, write the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
DECLARE @Name varchar(50), @Password varchar(50) -- Declare cursor with name my_cursor DECLARE my_cursor CURSOR LOCAL SCROLL STATIC FOR -- select recored from table Select Name, Password FROM Login_table -- open declared cursor OPEN my_cursor FETCH NEXT FROM my_cursor INTO @Name, @Password -- print the name PRINT @Name + ' from ' + @Password WHILE @@FETCH_STATUS = 0 BEGIN FETCH NEXT FROM my_cursor INTO @Name, @Password -- print the name PRINT @Name + ' from ' + @Password END -- close the cursor CLOSE my_cursor DEALLOCATE my_cursor |
HostForLIFE.eu SQL Server 2016 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. They deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. They have customers from around the globe, spread across every continent. They serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.