The parameter '@ statement' is 'ntext/nchar/nvarchar'

Source: Internet
Author: User

Create procedure [dbo]. [wl_sp_orderlist_count]
@ Bs_code varchar (20 ),
@ Ac varchar (20 ),
@ Recordcount int output
As
Set nocount on
Begin
Declare @ SQL varchar (1000)
Declare @ whe varchar (100)

If (@ ac = 'no ')
Set @ whe = 'and order_bs_state = 0'
Else
Set @ whe =''
Set @ SQL = 'select @ recordcount = count (*) from hc_order_list where order_bs_user_code = ''' + @ bs_code + ''' + @ whe
-- Print @ SQL
Exec sp_executesql @ SQL, n' @ recordCount int out', @ recordCount out
Set nocount off
End
GO

ASP calls are as follows:

Set CmdSp = Server. CreateObject ("ADODB. Command ")
CmdSP. ActiveConnection = Conn
CmdSp. CommandText = "wl_sp_orderlist_count"
CmdSp. CommandType = 4
CmdSp. Prepared = True
CmdSp. Parameters. Append CmdSp. CreateParameter ("@ bs_code", 200,1, 8, Bs_User_Code)
CmdSp. Parameters. Append CmdSp. CreateParameter ("@ ac", 200,1, 4, ac)
CmdSp. Parameters. Append CmdSp. CreateParameter ("@ recordcount", 3, 2, 4)
CmdSp. Execute
GetCount = CmdSp (2)
Set CmdSp. ActiveConnection = Nothing
Set Cmdsp = Nothing
Error message!
The parameter '@ statement' is of the 'ntext/nchar/nvarchar 'type.
Where are the issues?

Solution: declare @ SQL nvarchar (4000)

========================================================== ======================================
Nchar (n)
Unicode data with a fixed length of n characters. The value of n must be between 1 and 4,000. The storage size is twice the size of n Bytes. The synonyms of nchar in the SQL-92 are national char and national character.
Nvarchar (n)
Unicode data with a variable length of n characters. The value of n must be between 1 and 4,000. The storage size of bytes is twice the number of input characters. The length of the input data can be zero. The synonym for nvarchar in the SQL-92 is national char varying and national character varying.

Note

If n is not specified in the data definition or variable declaration statement, the default length is 1. If n is not specified by the CAST function, the default length is 30.
If you want the sizes of all data items in the column to be close to the same, use nchar.
Nvarchar is used if you want the data items in a column to vary greatly.
Objects that use nchar or nvarchar are assigned the default sorting rules of the database, unless the COLLATE clause is used to assign specific sorting rules.
SET ANSI_PADDING OFF is not applicable to nchar or nvarchar. SET ANSI_PADDING ON always applies to nchar and nvarchar.

2. char and varchar

Data Types of fixed-length (char) or variable-length (varchar) characters.
Char [(n)]
Character data with a fixed length of n Bytes and is not Unicode. N must be a value between 1 and 8,000. The storage size is n Bytes. The synonym for char in the SQL-92 is character.
Varchar [(n)]
Variable-length and non-Unicode character data with a length of n Bytes. N must be a value between 1 and 8,000. The storage size is the actual length of the input data bytes, rather than n Bytes. The length of the input data can be zero. The synonym for varchar in the SQL-92 is char varying or character varying.

Note
If n is not specified in the data definition or variable declaration statement, the default length is 1. If n is not specified by the CAST function, the default length is 30.
The default database sorting rules will be assigned to objects using char or varchar unless a specific sorting rule is assigned to the COLLATE clause. This sorting rule controls the code page used to store character data.

For websites that support multiple languages, Unicode nchar or nvarchar data types should be considered to minimize character conversion issues. If char or varchar is used:
If you want the data values in the column to be close to the same size, use char.
If you want the data values in the column to be significantly different, use varchar.
If SET ANSI_PADDING is OFF when you execute create table or alter table, a char column defined as NULL will be processed as varchar.
When the collation code page uses double-byte characters, the storage size is still n Bytes. Depending on the string, the storage size of n Bytes may be less than n characters.

Summary:

1. varchar:
Variable-length non-Unicode data, which can contain a maximum of 8,000 characters.
2. nvarchar:
A variable-length Unicode data with a maximum length of 4,000 characters.
3. char:
A fixed length of non-Unicode characters. The maximum length is 8,000 characters.
4. nchar
Unicode data of a fixed length. The maximum length is 4,000 characters.
5. char and varchar are both string types.
A string encoded in Unicode. The result is an integer of the character.

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.