"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)