sql server 的日期转格式。
现在sqlserver2008中的BO_ZH_WBX_S.RQ有一组数据如下:(select RQ from BO_ZH_WBX_S)
RQ
2013-12-06 00:00:00.000
2013-12-05 00:00:00.000
2013-12-10 00:00:00.000
利用下面sql语句先转换格式再拼接成一个字符@str
declare @str varchar(8000)
select @str=''
select @str=@str+cast(BO_ZH_WBX_S.RQ as varchar(32))+',' from BO_ZH_WBX_S
select @str as email
go
执行结果确实这样:
12 6 2013 12:00AM,12 5 2013 12:00AM,12 10 2013 12:00AM,
我想要的效果是是:
2013-12-06,2013-12-05,2013-12-10
谢谢大神。
------解决方案--------------------改成这样就行:
declare @str varchar(8000)
select @str=''
select @str=@str+
convert(varchar(10),BO_ZH_WBX_S.RQ,120)+',' from BO_ZH_WBX_S
select @str as email
go
------解决方案--------------------
create table BO_ZH_WBX_S(RQ datetime)
insert into BO_ZH_WBX_S
select '2013-12-06 00:00:00.000' union all
select '2013-12-05 00:00:00.000' union all
select '2013-12-10 00:00:00.000'
declare @str varchar(8000)
select @str=isnull(@str+',','')+convert(varchar,RQ,23)
from BO_ZH_WBX_S
select @str 'email'
/*
email
-------------------------------------
2013-12-06,2013-12-05,2013-12-10
(1 row(s) affected)
*/