Skip to main content

Posts

Showing posts from September, 2013

Tips to increase your Transact-SQL efficiency Part 1.

Given below are little known tips that you can use to ensure your Transact-SQL queries are performing in the  most efficient manner possible. 1. Avoid '*' in select query.      Restrict the queries result set by returning only the particular columns from the table and not all the  table's columns. The sql query becomes faster if you use the actual column names in SELECT  statement instead of than '*'. 2. Avoid COUNT(*) in select statement to check the existence of records in table.       Instead use IF EXISTS() to check records. - Write the query as: IF EXISTS (SELECT * FROM table_name WHERE column_name = ‘xxx’) - Instead of : SELECT COUNT(*) FROM table_name WHERE column_name = ‘xxx’ 3. Use alternate of SELECT COUNT(*).      Use an alternative way instead of the SELECT COUNT(*) statement to count the number     of records in  table.         - SELECT CO...

Importing the Excel into the Database (SQL).

We can import the excel into the Database by using the following query. Suppose we have a table named as Address_Temp and it has three column. 1. Name 2. State 3. Zip Here we need to update the zip code with the new value and to update that zip code we need to check the excel. So we can use that excel in our sql server by importing it using the following command. Its very easy query but make sure that it won't work in following two scenarios. 1. The file need to be in local machine. 2. The file should not be password protected. Declare @ ZipTemp NVarchar ( 255 ) set @ ZipTemp = ( SELECT * FROM OPENROWSET ( 'Microsoft.Jet.OLEDB.4.0' , 'Excel 8.0;Database=C:\Addresses.xls;IMEX=1' , 'SELECT top 1 ZIP FROM [Sheet1$] where ZIP = "328301"' ))

Simple Pyramid in Csharp .Net

    *   ***  ***** ******* Updated  As you can see below the code for simple pyramid has two for loop nested in each other. So for each row it enter, it increment the counter and draw the star against forming a pyramid like figure. You can use  different special counter, play with the loop and enjoy the coding. Simple Pyramid in Csharp    class Program     {          static void Main( string [] args)         {             int row, col = 0, n = 5;                                 for (row = 0; row <= n; row++)             {           ...