SQL varchar vs varchar (n)

Source: Internet
Author: User
Tags getdate

"title": SQL varchar varchar (n)
"Date": 2016-07-04
"category": SQL Server
"Problem": T-SQL declares variable type varchar after executing INSERT statement insert is unsuccessful
Reason: declaring variable varchar without length, SQL Server defaults to length 1 instead
Http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/09/bad-habits-to-kick-declaring-varchar-without-length.aspx
"How To find":

Declare @f_accounts varcharSet @f_accounts='H6155'MERGE intoT_othercredit astusing (SELECT @f_accounts  asf_accounts) asS on(t.f_accounts=S.f_accounts and Datediff(d, T.f_date,Getdate())= 0) when  notMatched ThenINSERT(f_accounts,f_date)VALUES(@f_accounts,Getdate()) ;--execute T-SQL after querySELECT * fromT_othercreditWHERE Datediff(d, F_date,Getdate())= 0 andF_accounts= 'H6154'

No data, however, direct substitution of @f_accounts for literal queries to normal data

"Fix": Declare @f_accounts varchar (20)

"In which files have been modified": none

"I cause": Yes

"Time to fix the bug": 2016-07-04 13:10

"Lesson": SQL Server or a simple understanding phase

SQL varchar vs varchar (n)

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.