SQL2000数据库,要将表1、表2中相同日期的String字段合并后写入表3同一日期的String字段中。
如果是Integer或Real等数据类型,则可用
Sum(xxx).....Group BY 日期
达到目的,但如果是String数据类型,应用什么语句实现?
同时
要将数据累加到记录中,如果是数字(integer、real等),则可直接用如下SQL语句:
update table set xx=xx+newdata where condiction
如果是string类型,SQL语句要如何写?
如果是Integer或Real等数据类型,则可用
Sum(xxx).....Group BY 日期
达到目的,但如果是String数据类型,应用什么语句实现?
同时
要将数据累加到记录中,如果是数字(integer、real等),则可直接用如下SQL语句:
update table set xx=xx+newdata where condiction
如果是string类型,SQL语句要如何写?
比如
update table set xx=xx+'123' where condiction
CAST(‘1’ as int)或CONVERT(int ,1)
可能不对 看下帮助
比如
update table set xx=xx+'123' where condiction Char数据类型是不行的,VarChar没有试,不知行不行!大家都说用Convert,看了下Help,没看明白,有示例吗?
update table set xx=xx+'123' where condiction
但要将表1、表2中相同日期的String字段合并后写入表3同一日期的String字段中。
如果是Integer或Real等数据类型,则可用
Sum(xxx).....Group BY 日期
达到目的,但如果是String数据类型,应用什么语句实现?
create table 表(部门 int,人员 varchar(20))
insert into 表 select 1,'张三'
insert into 表 select 1,'李四'
insert into 表 select 1,'王五'
insert into 表 select 2,'赵六'
insert into 表 select 2,'邓七'
insert into 表 select 2,'刘八'
go--创建用户定义函数
create function f_str(@department int)
returns varchar(8000)
as
begin
declare @ret varchar(8000)
set @ret = ''
select @ret = @ret+','+人员 from 表 where 部门 = @department
set @ret = stuff(@ret,1,1,'')
return @ret
end
go
--执行
select 部门,人员=dbo.f_str(部门) from 表 group by 部门 order by 部门
go--输出结果
/*
部门 人员
---- --------------
1 张三,李四,王五
2 赵六,邓七,刘八
*/
索引不定长的字段类型要用varchar ,固定长度的字段类型要用char