变量@holidays 是页面传过来的值是这样的格式:2011-02-18,2011-02-19,2011-02-20
我要在存储过程里面把@holidays这个字段格式转换成: '2011-02-18','2011-02-19','2011-02-20' 用另外的变量接收里面传过来日期个数不固定
我要做删除操作 where DATA in (@holidays) 如果这里直接传@holidays肯定不行的,现在我不会转换了,该怎么写
我要在存储过程里面把@holidays这个字段格式转换成: '2011-02-18','2011-02-19','2011-02-20' 用另外的变量接收里面传过来日期个数不固定
我要做删除操作 where DATA in (@holidays) 如果这里直接传@holidays肯定不行的,现在我不会转换了,该怎么写
select replace(''''+'2011-02-18,2011-02-19,2011-02-20'+'''',',',''',''')/*
--------------------------------------
'2011-02-18','2011-02-19','2011-02-20'
是这个意思
如果
select ''''+replace('2011-02-18,2011-02-19,2011-02-20',',',''',''')+''''
不给固定值,2011-02-18,2011-02-19,2011-02-20,用变量@holidays
要怎么写
declare @holidays varchar(200)='2011-02-18,2011-02-19,2011-02-20'
declare @TT table(date datetime)while(LEN(@holidays)>0)
begin
insert into @TT(date)
select LEFT(@holidays,10)
--select LEN(@holidays)-11
if(LEN(@holidays)-11<0)
begin
set @holidays=''
end
else
begin
set @holidays=RIGHT(@holidays,LEN(@holidays)-11)
end
end
select * from MyTable where date in (select date from @TT)
select replace(''''+@holidays+'''',',',''',''')