Search This Blog

Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Thursday, 25 August 2022

SQL Cursor Syntax - Quick Tech Bits

 Cursor: 

  • Is used to do a different processing row by row of the select query
  • The column names displayed need to be formatted or validated or processed before showing output. This process can give different results per row. 
  • Hence cursor is used

Eg: Showing culture specific / language specific outputs for the same data. Here cursor can be used

Eg: Creating a comma-separated string for a given table data


- TIP: Imagine you are working with a file when writing the cursor syntax. Makes it easier to visualize and understand the syntax

- File is created, then opened, then processed line-by-line, then closed and removed from memory.

- The same holds for a cursor


- SYNTAX

1.     DECLARE <cursorName> CURSOR FOR
2.               <select query>
3.     OPEN <cursorName>
4.     FETCH NEXT FROM <cursorName>
5.     INTO <variable names one each for selected  columns>
6.    
7.     <your logic for processing>
8.    
9.     CLOSE <cursorName>
10.   DEALLOCATE <cursorName>

*** CURSOR SHOULD ALWAYS BE USED AS THE LAST RESORT 

*** DUE TO PERFORMANCE CONCERNS

Check this repo for an example script of the MoviesDb and run the Cursor example.

The script files below should be run in Microsoft SQL Management Studio / Visual Studio in the same order.

MoviesDB Script: Creates a MoviesDB database with sample data

Cursor Script: Contains an example for cursor & how it can be replaced with a normal SQL query.

Hope this helps.

Wednesday, 19 August 2020

A fun session on blogger to aspiring ladies & gentlemen

 


The above is a screenshot of our session on what is blogging & blogger for Beginners session.

In our attempt to get ready for the Post-Covid Era, here was my small contribution to empower women & men alike to get more tech-savvy by having an online presence.

Was fun training aspiring ladies and gentlemen on blogging & getting them tech-savvy!

Got them to eventually create their own blogs & get blogging.

Was nice to see the excitement and enthusiasm to come out of their comfort zone towards to greater goal.


#fun #blogging #happytohelp #empowerwomen #gentlemen #gettechsavvy #prepare #forpostcovidera #ttot3

Wednesday, 5 December 2012

Tip: Hosts File Error:: "Please check if this file is opened in another program"

Editing a host file entry required administrator rights.
The host file can be opened in notepad as a plain text file.

If you directly open the hosts file in notepad, (Without using Run As Administrator), you will encounter the following error.


Run Notepad As Administrator, then open the hosts file in notepad

You can then edit and save your host entries.