Monday, March 30, 2009

SQL SCRIPT BANK

Hi this link to Pinal dev(MVP) 's scirpt bank.

SQL SCRIPT BANK




CREATE PROCEDURE [dbo].[tESTrEP]

AS
BEGIN

select
Jobrequest.jobid,
Jobrequest.jobTitle,
jobrequest.jobstatusid,
CONVERT(VARCHAR(11),RequestDate,103)[RequestDate],
count(jobrequest.jobTitle)[ToBeHire]
from candidate,jobrequest,Department,JobApplication
where
jobrequest.jobid=jobapplication.jobId and
jobapplication.candidateId=candidate.candidateId and
Department.DepartmentId=Jobrequest.DepartmentId and
Candidate.candidatestatustypeid = 5

group by(jobrequest.jobTitle),Jobrequest.jobid,jobrequest.jobstatusid,
CONVERT(VARCHAR(11),RequestDate,103)
compute sum(count(jobrequest.jobTitle))
END
Hi this is very clear difference
@@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT

I Copied it from following link
blog.sqlauthority.com/

SELECT @@IDENTITY
It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.
@@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it.

SELECT SCOPE_IDENTITY()
It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.
SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.

SELECT IDENT_CURRENT(’tablename’)
It returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.

To avoid the potential problems associated with adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your T SQL Statement or Stored Procedure.

Thursday, March 19, 2009

some sql server points

Question: what is cascade and restrict in drop table sql
Answerr:The CASCADE and RESTRICT keywords specify the action to be taken if other objects exist that are
dependent on the object being dropped. If CASCADE is specified, such objects will be dropped as well. If
RESTRICT is specified, an error is returned if other objects are affected, and no objects are dropped.
Question: How to import table using "INSERT" statement.
Answer : INSERT INTO new_table (Foo, Bar, Fizz, Buzz)SELECT Foo, Bar, Fizz, Buzz FROM source_table --
optionally WHERE ...
Question : what are DML,DDL,DCL,TCL Commands.
Answer:
DML is abbreviation of Data Manipulation Language. It is used to retrieve, store, modify, delete, insert and
update data in database.
Examples: SELECT, UPDATE, INSERT statements
DDL
DDL is abbreviation of Data Definition Language. It is used to create and modify the structure of database
objects in database.
Examples: CREATE, ALTER, DROP statements
DCL
DCL is abbreviation of Data Control Language. It is used to create roles, permissions, and referential
integrity as well it is used to control access to database by securing it.
Examples: GRANT, REVOKE statements
TCL
TCL is abbreviation of Transactional Control Language. It is used to manage different transactions occurring
within a database.
Examples: COMMIT, ROLLBACK statements
question: What is Ties in sql statement.
Answer:
TOP (expression) [PERCENT] [ WITH TIES ]
PERCENT Indicates that the query returns only the first expression percent of rows from the result set.
WITH TIES Specifies that additional rows be returned from the base result set with the same value in the ORDER BY columns
appearing as the last of the TOP n (PERCENT) rows. TOP...WITH TIES can be specified only in SELECT statements,
and only if an ORDER BY clause is specified.
The following example obtains the top 10 percent of all employees with the highest salary and returns them in
descending order according to salary base rate. Specifying WITH TIES makes sure that any employees that have
salaries equal to the lowest salary returned are also included in the result set, even if doing this exceeds 10
percent of employees.
Copy CodeUSE AdventureWorks;GOSELECT TOP(10) PERCENT WITH TIESc.FirstName, c.LastName, e.Title, e.Gender, r.RateFROM Person.Contact AS c INNER JOIN HumanResources.Employee AS e ON c.ContactID = e.ContactID INNER JOIN HumanResources.EmployeePayHistory AS r ON r.EmployeeID = e.EmployeeIDORDER BY Rate DESC;
Thanks
HELPONDESK TEAM

Wednesday, March 18, 2009

some important points for always remmber.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SELECT @@IDENTITY
It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.
@@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it.
SELECT SCOPE_IDENTITY()
It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.
SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.
SELECT IDENT_CURRENT(’tablename’)
It returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.
To avoid the potential problems associated with adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your T SQL Statement or Stored Procedure.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Refresh your page after every 6 second:


[meta http-equiv="refresh" content="6"]
[meta http-equiv="refresh" content="10;URL=Default2.aspx" /]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Find control in master page:: Master.FindControl("lbl")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Load master page dynamicaly::
protected void Page_PreInit(object sender, EventArgs e)
{
this.MasterPageFile = "MasterPage2.master";
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Why only one runat server form only one time in pae

in asp.net page::
1. The form is always submitted to the page itself. If you specify an action attribute, it is ignored. If you omit the method attribute, it will be set to method="post" by default. Also, if you do not specify the name and id attributes, they are automatically assigned by ASP.NET.
If you select view source in an .aspx page containing a form with no name, method, action, or id attribute specified, you will see that ASP.NET has added these attributes to the form. It looks something like this:

...some code


2.All server controls must appear within a

tag, and the tag must contain the runat="server" attribute. The runat="server" attribute indicates that the form should be processed on the server. Eg. If we put a button inside a form tag without runat="server" then its click event give an
Error:'Button' must be placed inside a form tag with runat=server
3. But one can create more then one form tag with runat="server". Using the visible property to set visible one at a time.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Differece Between Cast And Convert::
1. The difference is CAST is more ANSI standard and use this only if you are writing a program which you will need to use in many database platforms. Where CONVERT is Microsoft specific and more powerful.
2. Convert can used to format datatype but Cast can not do so.
SELECT GETDATE() AS UnconvertedDateTime, CAST(GETDATE() AS nvarchar(30)) AS UsingCast, CONVERT(nvarchar(30), GETDATE(), 126) AS UsingConvertTo_ISO8601
3. Cast can be used in the like command.
SELECT p.FirstName, p.LastName, s.SalesYTD, s.SalesPersonID FROM Person.Contact p JOIN Sales.SalesPerson s ON p.ContactID = s.SalesPersonID WHERE CAST(CAST(s.SalesYTD AS int) AS char(20)) LIKE '2%';
4. The CAST function is much better at preserving the decimal places when converting decimal and numeric data types. Most of developers and DBA’s that I have come across prefer to us the CAST function although CONVERT tends to be a bit for useful since it allows you to format the output.

Thanks

Helpondesk Team

Saturday, March 14, 2009

Virtual method call at runtime

The virtual mechanism (as you

correctly depicted as being implemented through a V-table) ensures

that the virtual method will be called no matter the type of the

reference you're using to call the method. Consider this example:


class A
{
public void M()
{
Console.WriteLine("A.M() being called");
}

public virtual void N()
{
Console.WriteLine("A.N() being called");
}
}

class B : A
{
public new void M()
{
Console.WriteLine("B.M() being called");
}

public override void N()
{
Console.WriteLine("B.N() being called");
}
}


say

A a = new B();

a.M();
a.N();


The results would be

A.M() being called
B.N() being called

because M() is called based on the compile time type (I am declaring

a as being an A) and N() is called based on the runtime type (after

all a is a B). Virtual introduces an method call indirection by

using a pointer to the method instead of the method itself. Because

of that the call is slower. C#, like C++ chose to be flexible in

this area, introducing the virtual keyword and retain the best of

both worlds (speed vs polymorhism) whereas, for instance Java,

considers all instance methods as virtual.