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

求sql 方法 - MS-SQL Server / 疑难问题

表A 
Field A1(Varchar) A2
record 1 1
record 2 1
record 3 1

表B
Field B1(Varchar) B2
record 1,2,5,6 1


要求,查找出 A1表中A1字段的值,在B表B1中,条件A2=B2
SQL code:
select a1 from a where exists(select 1 from b where charindex(','+ltrim(a.a1)+',',','+b1+',')>0 and a.a2=b2)


如何返回

for xml path()

record 这东西是字段内容还是多余的?

select A.* from A , B where A2=B2 and charindex(','+A1+',',','+B1+',')>0

SQL code:
select A1
from 表A a
where exists
(select B1
from 表B b
where b.B2 = a.A2
and charindex(',' + a.A1 + ',', ',' + b.B1 + ',') > 0)


1.exists:用来过滤记录的,相当于条件
2.CHARINDEX函数返回字符或者字符串在另一个字符串中的起始位置。不存在返回 0;
  CHARINDEX函数调用方法如下: 
  CHARINDEX ( expression1 , expression2 [ , start_location ] )



SQL code:
select A1
from 表A a
left join 表B b
on a.A2 = b.B2
where charindex(',' + a.A1 + ',', ',' + b.B1


相关问答:

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 ......

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

现在有两张表:文章主表A(articleId,articleTitle),文章评论表B(commentId,articleId,commentTitle)
现在我想实现这样的功能:列出文章列表,其中每篇文章标题下面列出此文章的前2个文章评论,请问sql语句怎么写啊 ......

MS SQL作业问题 - MS-SQL Server / 应用实例

如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP

参考:http://hi.baidu.com/toiota ......

求一时间比较的SQL 指令 - MS-SQL Server / 基础类

表数据
COL1 COL2 COL2 COL4 COL5
----------------------------------------------------------------------------------------------
2010-05-05 00:00 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号