【发布时间】:2015-11-14 19:26:05
【问题描述】:
我有一个 sql 表,其中“Action”中的一列是 nvarchar(max)。该列可以有 HelloKitty_1.MP4 或 HeMan_2.MP4 或 SpiderMan_1.MP4、Hulk_4.MP4 等值。这里 1、2、1 就是我所说的 videoIndex。
我正在用 SQL 编写一个存储过程,我在其中传入 videoIndex (int),它会返回具有该索引的所有行。所以在上面的例子中,如果传入 1,它应该返回 HelloKitty_1.MP4 和 SpiderMan_1.MP4。
我执行了以下 sn-p,但收到此错误“将 varchar 值 '%_' 转换为数据类型 int 时转换失败。”
DECLARE @SearchPattern varchar(40)
SET @SearchPattern = '%' + '_' + @videoindex + '.MP4'
DECLARE @WatchVideoCount int;
SET @WatchVideoCount =
(SELECT count(*)
FROM [dbo].[VideoWatched]
WHERE
[Action] LIKE @SearchPattern)
SELECT @WatchVideoCount as TotalTimesUsersWatchedVideo, @videoindex as videoIndex
【问题讨论】:
标签: sql-server tsql sql-like