易截截图软件、单文件、免安装、纯绿色、仅160KB

求一句sql - MS-SQL Server / 疑难问题


a b
1 2  
2 2
3 2
4 2
5 2

where b=2 查询后结果为

1,2,3,4,5


SQL code:
select stuff((select a from tb where b=2 order by a for xml path('')),1,1,'')


SQL code:
declare @s varchar(8000)
set @s=''
select @s=@s+a+',' from tb where b=2


SQL code:
declare @s varchar(100)
select @s=isnull(@s+',','')+ltrim(a)from tb where b=2



SQL code:
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
create table [tb]([a] int,[b] int)
go
insert [tb]
select 1,2 union all
select 2,2 union all
select 3,2 union all
select 4,2 union all
select 5,2

select stuff((select ','+ltrim(a) from tb where b = t.b for xml path('')),1,1,'' )
from [tb] t
where b = 2
group by b

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


相关问答:

csv文件转换成sql导入到数据库,没有数据为何?

执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

数据以xml格式返回 - MS-SQL Server / 应用实例

从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式
XML code:
<folder state="unchecked" label="全部">
   <folder state="unchecked&qu ......

求一SQL - MS-SQL Server / 基础类

tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......

请教SQL语句查询问题? - MS-SQL Server / 基础类

我想查询出每天数据的最大的一个值。表的格式如下
表名: hisdata
字段 编号 值 状态 时间  
  Id value state dattime  
  101 32.3 0 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号