我有一个用逗号分隔的 varchar 字符串,我想在我的 SQL 脚本中使用它,但我需要与数据库中的 bigint 字段进行比较。需要知道转换它:
DECLARE @RegionID varchar(200) = null
SET @RegionID = '853,834,16,467,841,460,495,44,859,457,437,836,864,434,86,838,458,472,832,433,142,154,159,839,831,469,442,275,840,299,446,220,300,225,227,447,301,450,230,837,441,835,302,477,855,411,395,279,303'
SELECT a.ClassAdID, -- 1
a.AdURL, -- 2
a.AdTitle, -- 3
a.ClassAdCatID, -- 4
b.ClassAdCat, -- 5
a.Img1, -- 6
a.AdText, -- 7
a.MemberID, -- 9
a.Viewed, -- 10
c.Domain, -- 11
a.CreateDate -- 12
FROM ClassAd a
INNER JOIN ClassAdCat b ON b.ClassAdCAtID = a.ClassAdCAtID
INNER JOIN Region c ON c.RegionID = a.RegionID
AND a.PostType = 'CPN'
AND DATEDIFF(d, GETDATE(), ExpirationDate) >= 0
AND a.RegionID IN (@RegionID)
AND Viewable = 'Y'
这失败并出现以下错误:
Error converting data type varchar to bigint.
RegionID 在数据库中是一个 bigint 字段.. 需要将 varchar 转换为 bigint.. 有什么想法..?
提前谢谢了,
新杰克