Tuesday, August 7, 2012

SQL Query Part 2

Query 1.      Case stmt example

 Tables                           Query                                               Result
  EMP_JB
SELECT id
ANSWER
       
,job
===============
  ID JOB
,CASE
ID  JOB
STATUS
          
WHEN  job  =  'Sales'
         
     
10 Sales
THEN  'Fire'
10
Sales
Fire
 20 Clerk
ELSE  'Demote'
20
Clerk
Demote
       
END  AS  STATUS
FROM emp_jb;
Query 2. Fetch  first  "n"  rowsexample

 Tables                           Query                                               Result

EMP_NM
SELECT
*
ANSWER
         
FROM
emp_nm
=========
 ID NAME
ORDER  BY  id  DESC
ID  NAME
            
FETCH  FIRST  2  ROWS  ONLY;
          
 10 Sanders  
50
Hanes
 20 Pernal    
20
Pernal
 50 Hanes
  


SQL Query Part 1

Query 1.      Join example

 Tables                           Query                           Result

Table 1                 Table 2 
EMP_NM
 EMP_JB
SELECT
nm.id
ANSWER
,nm.name
================
ID NAME
  ID JOB
,jb.job
ID  NAME
JOB
FROM
emp_nm  nm
 
10 Sanders
10 Sales 
,emp_jb  jb
10
Sanders
Sales
20 Pernal  
20 Clerk 
WHERE
nm.id  =  jb.id
20
Pernal
Clerk
50 Hanes
ORDER  BY  1;

Query 2.    Leftouterjoin  example

 Tables                           Query                           Result


Table 1                 Table 2 
EMP_NM
  EMP_JB
SELECT
nm.id
ANSWER
,nm.name
================
ID NAME
   ID JOB
,jb.job
ID  NAME
JOB
  
  
FROM
emp_nm  nm
 
10 Sanders 
10 Sales
LEFT  OUTER  JOIN
10
Sanders
Sales
20 Pernal  
20 Clerk
emp_jb  jb
20
Pernal
Clerk
50 Hanes
ON
nm.id  =  jb.id
50
Hanes
ORDER  BY  nm.id;

Monday, August 6, 2012

C Programming Question Part 3

Pattern Print with Unique and Extreme Logic
 Pattern  1. ***
**
*
**
***
 Code: #include <stdio.h>
main()
{


int i,x,j;
for (i=2; i>=-2;i--)
{

x = 1 + 2*abs(i);
for (j=1;j<=x;j++) printf("*");
printf("\n");

}
}
 Pattern 2. RAJVEER
A        E     
J        E
V        V
E        J
E        A
REEVJAR
 Code:  #include<conio.h>
#include<string.h>
void main()
{
     char str[20];
      int i,j,k,len;
      printf("Enter the String: ");
      gets(str);
      len=strlen(str);
      puts(str);
      printf("");
      for(i=1;i<len-1;i++)
      {
            printf("%c",str[i]);
            for(j=0;j<len-2;j++)
                  printf(" ");
            printf("%c\n",str[len-i-1]);
      }
      strrev(str);
      puts(str);
}
Pattern 3. *
 **
   ***
 **
*
Code: #include <stdio.h>
main()
{


int i,x,j;
for (i=2; i>=-2;i--)
{

x = 1 + abs(i);
for (j=1;j<=x;j++) printf(" ");
for (j=1;j<=x;j++) printf("*");
printf("\n");

}
}
Pattern 4. 1
01
101
0101
Code: #include<stdio.h>
#include<conio.h>

void main()
{
  int i,j;
  int count = 1;
  clrscr();
  for(i=1;i<=4;i++)
  {
        for(j=1;j<=i;j++)
        {
            printf("%d",(i+j+1)%2);               
        }
    printf("\n");   
  }
  getch();
}

C Programming Questions Part 2

Find The Outputs for Questions:

Que 1.
int main()
{
    int x,y=2,z;
    if ( x = y%2)
         z =2;
    a=2;
    printf("%d %d ",z,x);
    return 0;
}
Output:    Garbage 0 
Explanation:
This question has some stuff for operator precedence. If the condition of if is met, then z will be initialized to 2 otherwise z will contain garbage value. But the condition of if has two operators: assignment operator and modulus operator. The precedence of modulus is higher than assignment. So y%2 is zero and it’ll be assigned to x. So the value of x becomes zero which is also the effective condition for if. And therefore, condition of if is false.


Que 2.
int main()
{
    int a[10];
    printf("%d",*a+1-*a+3);
    return 0;
}
Output:      4
Explanation:
From operator precedence, de-reference operator has higher priority than addition/subtraction operator. So de-reference will be applied first. Here, a is an array which is not initialized. If we use a, then it will point to the first element of the array. Therefore *a will be the first element of the array. Suppose first element of array is x, then the argument inside printf becomes as follows. It’s effective value is 4.

a + 1 – a + 3 = 4


Que 3.
int main()
{
    static int i=5;
    if(--i){
        main();
        printf("%d ",i);
    }  
}
Output:      0 0 0 0
Explanation:
Since i is a static variable and is stored in Data Section, all calls to main share same i.

Que 4.
int main()
{
    int x;
    printf("%d",scanf("%d",&x));
    /* Suppose that input value given
        for above scanf is 2 */
    return 1;
}
Output:      1
Explanation:
scanf returns the no. of inputs it has successfully read.

Que 5.
int main()
{
    unsigned int i=65000;
    while ( i++ != 0 );
    printf("%d",i);
    return 0;
}
Output:      1
Explanation:
It should be noticed that there’s a semi-colon in the body of while loop. So even though, nothing is done as part of while body, the control will come out of while only if while condition isn’t met. In other words, as soon as i inside the condition becomes 0, the condition will become false and while loop would be over. But also notice the post-increment operator in the condition of while. So first i will be compared with 0 and i will be incremented no matter whether condition is met or not. Since i is initialized to 65000, it will keep on incrementing till it reaches highest positive value. After that roll over happens, and the value of i becomes zero. The condition is not met, but i would be incremented i.e. to 1. Then printf will print 1.

C Programming Interview Question Part I



Que 1. What is an lvalue?
Ans. An lvalue is an expression to which a value can be assigned. The lvalue expression is located on the left side of an assignment statement, whereas an rvalue is located on the right side of an assignment statement. Each assignment statement must have an lvalue and an rvalue. The lvalue expression must reference a storable variable in memory. It cannot be a constant.
For instance, the following lines show a few examples of lvalues:
int x;
int* p_int;
x = 1;
*p_int = 5;
The variable x is an integer, which is a storable location in memory. Therefore, the statement x = 1 qualifies x to be an lvalue.
1 = x Here compiler generate the error because the left value is contact which cannot be assigned.
Que 2. What is an rvalue?
Ans. rvalue can be defined as an expression that can be assigned to an lvalue. The rvalue appears on the right side of an assignment statement. Unlike an lvalue, an rvalue can be a constant or an expression, as shown here: 
int x, y;
x = 1; /* 1 is an rvalue; x is an lvalue */
y = (x + 1); /* (x + 1) is an rvalue; y is an lvalue */
An assignment statement must have both an lvalue and an rvalue.Therefore, the following statement would not compile because it is missing an rvalue:
 int x;
 x = void_function_call() /* the function void_function_call() returns nothing */
If the function had returned an integer, it would be considered an rvalue because it evaluates into something that the lvalue, x, can store.
Que 3. What are enumerations?
Ans. They are a list of named integer-valued constants.
Example:       enum color { black , orange=4,yellow, green, blue, violet };
This declaration defines the symbols “black”, “orange”, “yellow”, etc. to have the values “1,” “4,” “5,” … etc.
The difference between an enumeration and a macro is that the enum actually declares a type, and therefore can be type checked.
Que 4. What are register variables? What are the advantages of using register variables?
Ans. If a variable is declared with a register storage class, it is known as register variable.
The register variable is stored in the cpu register instead of main memory.
Frequently used variables are declared as register variable as it’s access time is faster. 
For Eg.
register int x=90;
Que 5. What do you know about Storage classes?
Ans. A storage class defines the scope (visibility) and life time of variables and/or functions within a C Program.
There are following storage classes which can be used in a C Program
  • auto
  • register
  • static
  • extern

Sunday, August 5, 2012

Installation of MS SQL Server - 2008




SQL SERVER – 2008 – Step By Step Installation


Note: - 
Before installing SQL Server 2008, you need to install the .Net Framework 3.5 (or higher).
If you have got installed the Microsoft Visual Studio 2008/2010 then you can start SQL Server 2008 Installation. If you've not got this installed already, then see the following PDF File.


You can Get Complete step by step Installation of Sql Server 2008 Installation Process from following Pdf File:









Set Session TimeOut In ASP.NET


We can Set or Manage Session Timeout in Following ways:
  
1.      Set Session TimeOut in Web.Config
We can set session timeout in SessionState section of web.config file as mentioned below, timeout value is in minutes.
<system.web>
    <sessionState mode="InProc" cookieless="false" timeout="15">
    </sessionState>
</system.web>
  
2.      Set session timeout in Global.asax

void Session_Start(object sender, EventArgs e)
{
  // Code that runs when a new session is started
  Session.Timeout = 15;
}