T-SQL tips

Source: Internet
Author: User
1. null value addition.
If null is added to other values (if varchar characters are used, the result is a null value. This is not expected in some composite character operations, so use the isnull function, if the value is null, a default value is assigned.
Example: declare @ location varchar (300)
Set @ location =''
Select
@ Location = isnull (Ri. Location ,''),
From job_resumeinfo ri
Where Ri. resumeid = @ resumeid

If the isnull function is not used and RI. Location is null, null is always returned. If the isnull function is added, ''is returned''
2. If the table field is left blank, dbnull must be used. Private Static bool isdbnull (idatareader DR, string name)
{
Int Index = dr. getordinal (name );
Return dr. isdbnull (INDEX );
}
Private Static string getstring (idatareader DR, string name)
{
If (! Isdbnull (DR, name ))
Return (string) Dr [name];
Return NULL;
}
Private Static int getint32 (idatareader DR, string name)
{
If (! Isdbnull (DR, name ))
Return (INT) Dr [name];
Return 0;
}
Private Static datetime getdatetime (idatareader DR, string name)
{
If (! Isdbnull (DR, name ))
Return (datetime) Dr [name];
Return datetime. now;
}
Private Static bool getboolean (idatareader DR, string name)
{
If (! Isdbnull (DR, name ))
Return (bool) Dr [name];
Return false;
}
Private Static guid getguid (idatareader DR, string name)
{
If (! Isdbnull (DR, name ))
Return (guid) Dr [name];
Return guid. empty;
}

3. If SQL2000 is originally installed with a default instance and sql2005 is to be installed, you must configure a custom instance for sql2005, or log on to the SA. If you use a custom instance, you must add the name of the custom instance after the server name when writing the connection string to the Enterprise Manager, for example, CJB \ sql2005.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.