Wednesday, 23 December 2015

how to schedule a job for sql query to run daily



  1. Expand the SQL Server Agent node and right click the Jobs node in SQL Server Agent and select 'New Job'
  2. In the 'New Job' window enter the name of the job and a description on the 'General' tab.
  3. Select 'Steps' on the left hand side of the window and click 'New' at the bottom.
  4. In the 'Steps' window enter a step name and select the database you want the query to run against.
  5. Paste in the T-SQL command you want to run into the Command window and click 'OK'.
  6. Click on the 'Schedule' menu on the left of the New Job window and enter the schedule information (e.g. daily and a time).
  7. Click 'OK' - and that should be it.
  8. Note :SQL Server express does not come with SQL Agent Feacture.

T-SQL loop over SQL Select query results

select @id=table.id from table and I need to loop over the results so I can exec a store  procedure for each row exec stored_proc @varName=@id,@otherVarName='test'

How can I do this in a T-SQL script?

You could use a CURSOR in this case:
DECLARE @id INT
DECLARE @name NVARCHAR(100)
DECLARE @getid CURSOR

SET @getid = CURSOR FOR
SELECT table.id,
       table.name
FROM   table

OPEN @getid
FETCH NEXT
FROM @getid INTO @id, @name
WHILE @@FETCH_STATUS = 0
BEGIN
    EXEC stored_proc @varName=@id, @otherVarName='test', @varForName=@name
    FETCH NEXT
    FROM @getid INTO @id, @name
END

CLOSE @getid
DEALLOCATE @getid
Cursor is a database objects to retrieve data from a result set one row at a time, instead of the T-SQL commands that operate on all the rows in the result set at one time. We use cursor when we need to update records in a database table in singleton fashion means row by row.

Cursor Flow

  1. Declare Cursor

    A cursor is declared by defining the SQL statement that returns a result set.
  2. Open

    A Cursor is opened and populated by executing the SQL statement defined by the cursor.
  3. Fetch

    When cursor is opened, rows can be fetched from the cursor one by one or in a block to do data manipulation.
  4. Close

    After data manipulation, we should close the cursor explicitly.
  5. Deallocate

    Finally, we need to delete the cursor definition and released all the system resources associated with the cursor.

Syntax of Cursor

Declare Cursor SQL Comaand is used to define the cursor with many options that impact the scalablity and loading behaviour of the cursor. The basic syntax is given below
  1. DECLARE cursor_name CURSOR
  2. [LOCAL | GLOBAL] --define cursor scope
  3. [FORWARD_ONLY | SCROLL] --define cursor movements (forward/backward)
  4. [STATIC | KEYSET | DYNAMIC | FAST_FORWARD] --basic type of cursor
  5. [READ_ONLY | SCROLL_LOCKS | OPTIMISTIC] --define locks
  6. FOR select_statement --define SQL Select statement
  7. FOR UPDATE [col1,col2,...coln] --define columns that need to be updated

Syntax to Open Cursor

A Cursor can be opened locally or globally. By default it is opened locally. The basic syntax to open cursor is given below:
  1. OPEN [GLOBAL] cursor_name --by default it is local

Syntax to Fetch Cursor

Fetch statement provides the many options to retrieve the rows from the cursor. NEXT is the default option. The basic syntax to fetch cursor is given below:
  1. FETCH [NEXT|PRIOR|FIRST|LAST|ABSOLUTE n|RELATIVE n]
  2. FROM [GLOBAL] cursor_name
  3. INTO @Variable_name[1,2,..n]

Syntax to Close Cursor

Close statement closed the cursor explicitly. The basic syntax to close cursor is given below:
  1. CLOSE cursor_name --after closing it can be reopen

Syntax to Deallocate Cursor

Deallocate statement delete the cursor definition and free all the system resources associated with the cursor. The basic syntax to close cursor is given below:
  1. DEALLOCATE cursor_name --after deallocation it can't be reopen

Tuesday, 22 December 2015

Exception of type 'System.OutOfMemoryException' was thrown after deploying Website in IIS.


This problem usually occurs when some process such as loading huge data to memory stream and your system memory is not capable of storing so much of data. Try clearing temp folder by giving the command

start -> run -> %temp%


Running in Debug Mode
When you're developing and debugging an application, you will typically run with the debug attribute in the web.config file set to true and your DLLs compiled in debug mode. However, before you deploy your application to test or to production, you should compile your components in release mode and set the debug attribute to false.
ASP.NET works differently on many levels when running in debug mode. In fact, when you are running in debug mode, the GC will allow your objects to remain alive longer (until the end of the scope) so you will always see higher memory usage when running in debug mode.
Another often unrealized side-effect of running in debug mode is that client scripts served via the webresource.axd and scriptresource.axd handlers will not be cached. That means that each client request will have to download any scripts (such as ASP.NET AJAX scripts) instead of taking advantage of client-side caching. This can lead to a substantial performance hit.

Monday, 14 December 2015


                                 How to Set an empty DateTime variable ?

I would declare an empty String variable like this:
    string myString = string.Empty;
Is there an equivalent for a 'DateTime' variable ?
Answer :

Since DateTime is a value type you cannot assign null to it, but exactly for these cases (absence of a value) Nullable<T> was introduced - use a nullable DateTime instead:
DateTime? myTime = null;

Wednesday, 16 September 2015



If you don't move, you lose by default.

If you move, you should think deeply about it or someone may push you over.

If you move well, you can protect the pieces you hold dear besides you.

If you're too far from your beloved, you may not make it back in time to protect them.

The path of survival and comfort takes great planning.

Brilliance and success comes to those that are most observant.

Adapting to the situation is the key to success.

Knowledge and experience are keen advantages.

You have a limited number of moves; make them good ones.

Wednesday, 9 September 2015



               Utilities for Web development 


  • Probably the best site for browser compatibility information is CanIUse.
  •  learn HTML and CSS from Codecademy.com.