2011-12-01 134 views
1

我想運行此查詢,但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 

回答

0

對於varchar[(n)]

當在數據定義或變量聲明 語句未指定n,則默認長度爲1。當不與 CAST函數指定n,則默認長度爲30

所以明確地在CAST,例如指定一個適當長的長度varchar(256)

Ref