选择结果不完整?

时间:2011-12-01 00:38:00

标签: sql sql-server-2008

我正在尝试运行此查询,但myfield不包含完整的电子邮件地址,姓氏,电话和电子邮件促销值?看起来myField的长度有限制吗?

sql语句:

use adventureworks 
go 

select si.CustomerID, 
'myField' = 
            CASE 
                 When (Select Top 1 FirstName+ ' ' + MiddleName + ' '+ Phone  + ' ' + EmailAddress  +' '+ LastName + ' ' + Phone + ' ' + cast(EmailPromotion as varchar)   From Person.Contact pc Where si.ContactID = pc.contactid ) is not null Then  
            Cast((Select Top 1 FirstName+ ' ' + MiddleName + ' ' + Phone  + ' ' +EmailAddress  +' '+ LastName + ' ' + Phone + ' ' + cast(EmailPromotion as varchar) From Person.Contact pc Where si.ContactID = pc.contactid  ) As varchar) 
            Else '' 
            END 

from Sales.Individual si 
where si.CustomerID=11000 

1 个答案:

答案 0 :(得分:0)

varchar[(n)]

  

在数据定义或变量声明中未指定n时   声明,默认长度为1。当未指定n时   CAST功能,默认长度为30。

CAST中明确指定适当长的长度,例如varchar(256)

Ref