Archive for the ‘Programming’ Category

Using OVER() with Aggregate Functions in Sql Server 2005

1.you can now add aggregate functions to any SELECT (even without a GROUP BY clause) by specifying an OVER() partition for each function.

2.SUM(..) OVER(..) is most useful for calculating a Total or percentage of a total for each row

3.SUM() function works with any of the other aggregate functions as well, such as MIN() or AVG()

Partition by

Divides the result set into partitions. The window function is applied to each partition separately and computation restarts for each partition.

select
StudentId,
StudentName,
Subject,
Mark,
sum(Mark) OVER (Partition by StudentId) as Total
from
Student

Output
=====
StudentId StudentName Subject Mark Total
======= ========== ===== ==== =====
1 Raja Physics 80 240
1 Raja Maths 90 240
1 Raja Biology 70 240
2 Sam Physics 90 150
2 Sam Maths 60 150

Popularity: 3% [?]

StringTokenizer in JAVA

The StringTokenizer class allows an application to break a string into tokens. The tokenization method is much simpler than the one used by the StreamTokenizer class. The StringTokenizer do not distinguish among identifiers, numbers, and quoted strings, nor do they recognize and skip comments.

The set of delimiters (the characters that separate tokens) may be specified either at creation time or on a per-token basis.

An instance of StringTokenizer behaves in one of two ways, depending on whether it was created with the returnDelims having the value True or False :

  • If the flag is Flase , delimiter characters serve to separate tokens. A token is a maximal sequence of consecutive characters that are not delimiters.
  • If the flag is True , delimiter characters are themselves considered to be tokens. A token is thus either one delimiter character, or a maximal sequence of consecutive characters that are not delimiters.

A StringTokenizer object internally maintains a current position within the string to be tokenized. Some operations advance this current position past the characters processed.

A token is returned by taking a substring of the string that was used to create the StringTokenizer object.

Example without Delimiter:-

StringTokenizer st = new StringTokenizer(“Example Of String Tokenizer”);
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}

Output
=====
Example
of
String
Tokenizer

Example with Delimiter:-

StringTokenizer st = new StringTokenizer(“1$2$3$4″,”$”);
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}

Output
=====
1
2
3
4

Popularity: 2% [?]

Create Database,Table and Procedure in Sql Server – Beginners

Database Creation :

CREATE DATABASE EMPLOYEE

Table Creation :

CREATE TABLE EMPINFO
(
ROWID INT IDENTITY(1,1) NOT NULL,
EMPID INT NOT NULL,
EMPNAME VARCHAR(50) NOT NULL,
EMPDEPT VARCHAR(3) NOT NULL,
EMPSAL INT NOT NULL,
EMPADDRESS VARCHAR(100) NOT NULL,
ACTIVE CHAR(1) NOT NULL DEFAULT ‘T’
)

Procedure Creation :

CREATE PROC EMPINFO_ADD_EDIT
(
@iEMPID INT,
@vEMPNAME VARCHAR(50),
@vEMPDEPT VARCHAR(3),
@iEMPSAL INT ,
@vEMPADDRESS VARCHAR(100),
@cACTIVE CHAR(1)
)
AS
DECLARE @CNT INT;
BEGIN
SET @CNT = 0;
SELECT @CNT = COUNT(*) FROM EMPINFO WHERE EMPID = @iEMPID;
IF(@CNT = 0)
BEGIN

INSERT INTO EMPINFO(EMPID,EMPNAME,EMPDEPT,EMPSAL,EMPADDRESS,ACTIVE)VALUES @iEMPID,@vEMPNAME,@vEMPDEPT,@iEMPSAL,@vEMPADDRESS,@cACTIVE)

END
ELSE
BEGIN

UPDATE EMPINFO SET EMPNAME = @vEMPNAME,EMPDEPT = @vEMPDEPT,EMPSAL = @iEMPSAL, EMPADDRESS = @vEMPADDRESS,ACTIVE = @cACTIVE WHERE EMPID = @iEMPID

END

END

Popularity: 2% [?]

Swapping a Number

SWAPPING WITHOUT TEMP:

#include <stdio.h>;
 
void main()
{
int a=20,b=30;
a=a+b;
b=a-b;
a=a-b;
printf("a=%d",a);
printf("b=%d",b);
}

SWAPPIG WITH TEMP:

#include <stdio.h>;
void main()
{
int a=20,b=30,temp;
temp=a;
a=b;
b=temp;
printf("a=%d",a);
printf("b=%d",b);
}

Popularity: 1% [?]

Palindrome For String And Numbers

Palindrome Checking Using C:

#include <stdio.h>
#include <conio.h>
#include <string.h>
#define size 26
 
void main()
{
char strsrc[size];
char strtmp[size];
printf("\n Enter String:= ");
gets(strsrc);
strcpy(strtmp,strsrc);
strrev(strtmp);
if(strcmp(strsrc,strtmp)==0)
printf("\n Entered string \"%s\" ispalindrome",strsrc);
else
printf("\n Entered string \"%s\" is not palindrome",strsrc);
getch();
}

Popularity: 1% [?]

Encrypting string value using MD5 in PHP

The md5 method is used to convert the string value into md5 value.
The syntax is,

string md5 ( string $str [, bool $raw_output ] )

Parameters

str : The string.
raw_output : If the optional raw_output is set to TRUE, then the md5 digest is instead returned in raw binary format with a length of 16. Defaults to FALSE.

For Example,

echo “The MD5 value of ‘ForDevelopers’ is ” . md5(“ForDevelopers”);

Popularity: 1% [?]

Check Sql Server database is Case Sensitive or Insensitive (Collation)

If the collation property of a data base is

1.Latin1_General_BIN its case-sensitive
2.SQL_Latin1_General_CP1_CI_AS or Latin1_General_CI_AI its case-insensitive

There are two ways to find out the SQL Server Database Collation

1. Using DATABASEPROPERTYEX

DATABASEPROPERTYEX gets the current setting of the specified database option or property for the specified database.

Syntax :-
DATABASEPROPERTYEX ( database , property )

SELECT DATABASEPROPERTYEX(‘testdb’, ‘Collation’)

This returns the testdb Database Collation property value say if this testdb is a case-sensitive database then it returns

Latin1_General_BIN

2.Using Sql Server Management Studio

Step 1 : Open Sql Server Management Studio.

Step 2 : Right Click on database and click its properties


After clicking the properties you get a database properties modal box such as

The red box shows the collation property value of that database.

Popularity: 3% [?]

Encrypting text value using MD5 in Dot Net

For example we will have two textboxes such as ‘TextBox1′ and ‘TextBox2′.Now we will encrypt ‘TextBox1′ value using MD5 in Dot Net and display the encrypted value in ‘TextBox2′.

string pwd = “”;
 
pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox1.Text, “MD5″);
 
TextBox2.Text = pwd;

Popularity: 1% [?]

Open a File in Runtime in Java

Open a File in Runtime in Java:

1.Create a Object For Process

2.exec is a method to open a File in Runtime

3.In the exec Method, we can give all the command which can be give in the Run Window

Process process=Runtime.getRuntime().exec(“notepad d:\demo.txt”);

4.If it cannot Work,Copy Exe File and Paste it in C:\Windows\System32

Popularity: 1% [?]

Conditional Tags in JSP

The if tag allows the conditional execution of its body according to the value of the test attribute

<c:if test=”${not empty details.add}”>
It is Not a Empty ArrayList
</c:if>

<c:if test=”${empty details.add}”>
It is a Empty ArrayList
</c:if>

The choose tag performs conditional block execution by the embedded when subtags. It renders the body of the first when tag whose test condition evaluates to true. If none of the test conditions of nested when tags evaluates to true, then the body of an otherwise tag is evaluated, if present.

<c:choose>
<c:when test=”${bank.account== ‘saving’}”>
Saving Account
</c:when>
<c:when test=”${bank.account == ‘RD’}”>
RD Account
</c:when>
<c:when test=”${bank.account == ‘salary’}”>
Salary Account
</c:when>
<c:otherwise>

</c:otherwise>
</c:choose>

Popularity: 1% [?]

Designed by: Business Web Hosting | Thanks to Buy Icons, travel tips and Used Cars