我正在尝试运行下面的脚本但是收到错误...
Msg 306,Level 16,State 2,Line 58
除非使用IS NULL或LIKE运算符,否则无法比较或排序text,ntext和image数据类型。
有人能告诉我哪里出错了。请温柔,因为我对这一切都是新手。 :)
提前致谢!
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
答案 0 :(得分:0)
您需要弄清楚您正在使用的列是text,ntext或image数据类型列。根据错误消息,您使用此数据类型的列进行排序或&#34;比较&#34;。在此查询中,该查询位于WHERE子句,联接的ON子句,ORDER BY子句,ORDER BY子句或可能在该CASE语句中。
完全根据colunn名称,我猜测它是source
或gift_aid
,但如果不审查架构则无法确定。
答案 1 :(得分:0)
错误表示第58行是“Cancellation_reason IS NULL”
也许您可以应用LEFT()来获取字符串,然后将其测试为null,例如
LEFT( m.cancellation_reason, 1 ) IS NULL
所以在这里,我只关心取消原因的第一个字符。如果它为null,它不会返回null吗?