易截截图软件、单文件、免安装、纯绿色、仅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 ......

Asp+sql server问题 - Web 开发 / ASP

我一个项目,有个插入操作,具体是这样的:
我有进货信息表。在出货时选择相应的进货信息,输入数量,选择部门后,点保存按钮,由于网络延时,点一下没有反映,于是用户就又点一下,导致一次插入了两条记录:
例: ......

SQL如何优化问题 - MS-SQL Server / 疑难问题

今天做了一个存储过程   环境是SQL2000数据库  
大致如下
建立临时表
定义员工游标
        循环员工(属于1个公司)  
        ......

请教SQLSERVER的两个问题 - MS-SQL Server / 疑难问题

1。怎样使xp_cmdshell能完整输出超过255个字符的字符串。
2。select 时,检索速度是与from后的 TABLE顺序有关,还是与where条件的顺序有关(TABLE数据多少 )
在系统属性设定里有个选项,可以修改单字段输出字数限制. ......

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

id                           url                   rank     ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号