sql 语句中where子句后面like的条件如果有变量怎么写表达式?举例:申明游标等……declare @id varchar(50)fetch next from my_cursor into @idupdate tablename01 set 总数=sum(数量) from tablename02 ……where 数量 like @id
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/06 05:27:24
sql 语句中where子句后面like的条件如果有变量怎么写表达式?举例:申明游标等……declare @id varchar(50)fetch next from my_cursor into @idupdate tablename01 set 总数=sum(数量) from tablename02 ……where 数量 like @id
sql 语句中where子句后面like的条件如果有变量怎么写表达式?
举例:
申明游标等……
declare @id varchar(50)
fetch next from my_cursor into @id
update tablename01 set 总数=sum(数量) from tablename02
……
where 数量 like @id+'%'
可是like后面的都要在单引号之中才行啊,应该怎么写啊?
sql 语句中where子句后面like的条件如果有变量怎么写表达式?举例:申明游标等……declare @id varchar(50)fetch next from my_cursor into @idupdate tablename01 set 总数=sum(数量) from tablename02 ……where 数量 like @id
declare @sql varchar(1000)
set @sql = 'update tablename01 set 总数=sum(数量) from tablename02
……
where 数量 like ''' + cast(@id as varchar(10) + '%'''
EXEC(@sql)