我試圖運行下面的腳本,但我得到一個錯誤的SQL錯誤...不確定如何解決
消息306,級別16,狀態2,行58
文本,ntext和圖像數據類型不能被比較或排序,除非使用IS NULL或LIKE運算符。
有人能告訴我我哪裏出錯了。請儘量溫柔,因爲我對這一切都很陌生。 :)
在此先感謝!
SELECT
c.address_number as address_number,
c.contact_number as contact_number,
c.label_name as contact_name,
a.address as address,
a.postcode as postcode,
s.source as source,
s.source_desc as source_desc,
m.joined as member_join_date,
m.membership_card_expires as member_expiry_date,
o.payment_method as payment_method,
pf.payment_frequency_desc as payment_frequency_desc,
pf.frequency as payment_frequency,
c.std_code as std_code,
c.telephone as phone_number,
gift_aid = CASE
WHEN gad.declaration_number IS NOT NULL then 'Y' else null end,
cp.first_payment_date as first_payment_date,
cp.last_payment_date as last_payment_date,
-- NUMBER OF DONATIONS IN THE LAST 12 MONTHS GOES HERE --
cp.value_of_payments as total_donation_amount
FROM
contacts c
INNER JOIN
contact_addresses ca ON c.contact_number = ca.contact_number
AND c.address_number = ca.address_number
INNER JOIN
addresses a ON ca.address_number = a.address_number
INNER JOIN
sources s ON c.source = s.source
INNER JOIN
contact_suppressions cs ON c.contact_number = cs.contact_number
INNER JOIN
orders o ON c.contact_number = o.contact_number
INNER JOIN
members m ON c.contact_number = m.contact_number
INNER JOIN
contact_categories cc ON c.contact_number = cc.contact_number
INNER JOIN
payment_frequencies pf ON o.payment_frequency = pf.payment_frequency
LEFT OUTER JOIN
gift_aid_declarations gad ON c.contact_number = gad.contact_number
AND (start_date IS NULL OR start_date < GETDATE())
INNER JOIN
contact_performances cp ON c.contact_number = cp.contact_number
WHERE
-- EXCLUSIONS --
c.status NOT IN ('DECD','AN','DU','GONE') AND
c.contact_number NOT IN (SELECT contact_number FROM contact_suppressions
WHERE mailing_suppression IN ('NOMA','APP','DATA')) AND
c.contact_number NOT IN (SELECT contact_number FROM contact_categories
WHERE activity IN ('MAJDON', 'PATRON', 'PCD11', 'PCT',
'PCAD12', 'PCAD13', 'PCFI13',
'PCHR12', 'PCIA12', 'PCNH12',
'PCSL13', 'PCSK13', 'PCTC13')) AND
ca.historical = 'N' AND
-- MEMEBRSHIP NOT CANCELLED --
m.cancellation_reason IS NULL
ORDER BY
address_number, contact_number, contact_name, address, postcode, source, source_desc, member_join_date,
member_expiry_date, payment_method, payment_frequency_desc, payment_frequency, std_code, phone_number, gift_aid, first_payment_date, last_payment_date, total_donation_amount
請確定哪些列是「text」,「ntext」或「image」。 – 2014-09-12 14:53:02
將在未來版本的SQL Server中刪除'ntext','text'和'image'數據類型。避免在新的開發工作中使用這些數據類型,並計劃修改當前正在使用它們的應用程序。改爲使用'nvarchar(max)','varchar(max)'和'varbinary(max)'。 [詳細請看這裏](http://msdn.microsoft.com/en-us/library/ms187993.aspx) – 2014-09-12 16:02:26