一个sql相减的问题 - MS-SQL Server / 疑难问题
一个字段是这样的 x 可以放多个值.. 传进来是字符串, ==> 12,13,14...20 如 select * from tableName where x in(12,13,14...20) 原始数据是这样..但是我想要得到 select * from tableName where x in(1,2,3...9)
也就是在原来的基础上减去11 ---?>>select * from tableName where x in(1,2,3...9)
没看明白 ,帮顶。
贴出表结构,数据
以及你要的结果
参考以下
SQL code:
create table #t(
id varchar(10))
declare @str varchar(300)
set @str='12,13,14,20'
declare @i int
declare @len int
set @i = 1
while @i < len(@str+',')
begin
insert #t select substring(@str+',',@i,charindex(',',@str+',',@i)-@i)
set @i = charindex(',',@str+',',@i)+1
end
select * from #t
/*
id
----------
12
13
14
20
(所影响的行数为 4 行)
*/
--drop table #t
create table a
(
id int identity(1,1) not null,
x int not null ----- 这个字段是保存1。..9 的数据 但是程序传过来的数据是 12,13,14...20 一个字符串
)
insert into a select 1 union all select 2 union all select 3 ,,,union all select 9
SQL code:
id varchar(10))
declare @str varchar(300)
set @str='12,13,14,20'
declare
相关问答:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
1。怎样使xp_cmdshell能完整输出超过255个字符的字符串。
2。select 时,检索速度是与from后的 TABLE顺序有关,还是与where条件的顺序有关(TABLE数据多少 )
在系统属性设定里有个选项,可以修改单字段输出字数限制. ......
需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......
通过NAME字段条件查询一个数据表,假设我有100个姓名,有以下两个方法,
方法1:
把100个Name 组成一个SQL语句,比如 Select * from tmp_table where Name='张三' or Name ='李四' Or ...Or Name='第一百个姓名'
......