有一个表a, 字段id(自增), type(int), shopid(int)
现在希望写一个存储过程.返回的结果是根据type返回shopid的串,格式是1,2,3,4这样的格式.
sql语句就象这样:select shopid from a where type=3,其中type=3中的3是输入参数
先谢谢啦..
现在希望写一个存储过程.返回的结果是根据type返回shopid的串,格式是1,2,3,4这样的格式.
sql语句就象这样:select shopid from a where type=3,其中type=3中的3是输入参数
先谢谢啦..
RETURNS varchar(1000)
AS
BEGIN
DECLARE @re varchar(100)
SET @re=''
SELECT @re=@re+','+CAST(shopid as varchar)
FROM 表A
WHERE type=@ID
RETURN(STUFF(@re,1,1,''))
END
GO--调用函数
SELECT type,shopid=dbo.f_str(type) FROM 表A GROUP BY type
@Type int
@Shopid varchar(8000) output
As
Declare @Shopidstr varchar(8000)select @Shopidstr=isnull(@Shopidstr,'')+Cast(shopid as varchar)+',' from
表A where type=@Typereturn @Shopidstr
请问:itblog(每天进步一点点),如果再加一个参数@endtime,表a中有一个字段endtime,希望加上条件endtime大于等于@endtime
以上该怎么改写呢?