Implicit conversions of ms SQL Server Stored Procedure Parameters

Source: Internet
Author: User

The columns and stored procedure parameters of Microsoft SQL Server 2000 data tables are of the type, but I found that many parameter types can be "mixed" when writing stored procedures, for example, the following stored procedure:

/**/ /*

Name: stp_testdifferentparatype_int

Function: test the impact of different parameter types on stored procedures.

Author: waxdoll Cheung

Date: 2005-04-07

*/


Create   Procedure DBO. stp_testdifferentparatype_int

-- Year and month

@ Tongjinianyue Int

As

  Select   [ FM _ product registration ] . *   From   [ FM _ product registration ]   Where (Year = @ Tongjinianyue)


  Return

Go



And the following stored procedure:

/**/ /*

Name: stp_testdifferentparatype_char

Function: test the impact of different parameter types on stored procedures.

Author: waxdoll Cheung

Date: 2005-04-07

*/


Create   Procedure DBO. stp_testdifferentparatype_char

-- Year and month

@ Tongjinianyue Char ( 4 )

As

  Select   [ FM _ product registration ] . *   From   [ FM _ product registration ]   Where (Year = @ Tongjinianyue)


  Return

Go



The output results are the same when testing the stored procedure, and the data column is of the type -- char (4 ),

Why? The stored procedure performs implicit type conversion on parameters during execution.

Note the following when determining the parameter type when writing a stored procedure:

1. Try to use the same data type as the data column to reduce the implicit type conversion;

2. Not all types can be implicitly converted. If different data types are used, an error may occur: 


Figure: data type conversion of Microsoft SQL Server

In addition, SQL Server user-defined function parameters are similar.

Related Article

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.