--建立测试表 tableA (type=“书籍”的不足100条),tableB (type=“书籍”的多于100条)
create table tableA(id int identity(1,1),type nvarchar(8))
create table tableB(id int identity(1,1),type nvarchar(8))
go
--向表tableA循环插入测试语句
declare @a int
set @a=0
while (@a<120)
begin
if @a<20
insert into tableA(type)values('报刊')--20本是'报刊'
else if @a<40
insert into tableA(type)values('光盘')--20本是'光盘'
else if @a<60
insert into tableA(type)values('漫画')--20本是'漫画'
else if @a<80
insert into tableA(type)values('书籍')--20本是'书籍'
else if @a<100
insert into tableA(type)values('其它')--20本是'其它'
else
insert into tableA(type)values('杂志')--20本是'杂志'
set @a=@a+1
end
go
--向表tableB循环插入测试语句
declare @b int
set @b=0
while (@b<120)
begin
insert into tableB(type)values('书籍')--全部是'书籍'
set @b=@b+1
end
go
--查看表tableA,tableB中的数据
select from tableA
select from tableB
/查看你要看的的数据/
--方法一,用charindex函数(当然函数里面的顺序可以根据自己要求改变)
select top 100 from tableA order by charindex(type,'书籍报刊漫画杂志光盘其它')
--方法二,如果在不想用函数可以同一楼一样用下面的方法
select top 100 from tableA order by case when type='书籍' then 1 when type='报刊' then 2 else 3 end
--tableB表同上
--查看完后删除测试表
drop table tableA
drop table tableB
数据我已经测试过了,没问题
最后求赏~~
String productsff="";
for(int i=0;i<productslength;i++){
productsff=productsff+" "+products[i];
}
pssetString(7,productsff);
在SQL数据中是不分位置的,这是它与其它数据库的不同之处,也就是说,它记录数据不管它的位置,只记录信息,这样SQL数据库中查询的时候就省去了从第一条到你要查的那一条所花费的时间,它会根据你的要求,自动选择最快的方式找到你要的数据。
所心你说要打第二条是行不通的,除非你通过它的ID或是其它来查询。
select top 10 from
(select top 30 from table order by id asc)
as a
order by id desc
排序字段 和排序方法 根据你的表数据调整一下
例 数据是如下形式
id
1
2
3
4
5
sql语句为
select top 2 from
(select top 4 from table order by id asc)
as a
order by id desc
得到的结果是
4
3
thisCheckBoxList1Items[i]Value即为选定的值,只需要将此值写入数据库即可。
假设已经连接数据库
在if中填入以下语句:
itemvalue=thisCheckBoxList1Items[i]Value;
sql="insert into DevelopRole(RoleTile) values('" + itemvalue + "')";
ExecuteSQLStmt(sql);
基本思路是这样,希望对你有帮助。
select
into
表
From
当Into后面的表存在时,就会报错,你可以改个别的名字,如果Into后面的名字是固定的,可以事先用Drop
Table命令删除它,再Select
into
如果数据是追加的,可以使用Insert
Into
Select
From命令,来追加数据前提是表
已经存在
以上就是关于数据库取值的sql语句全部的内容,包括:数据库取值的sql语句、servlet中获取选中的checkbox的值,如何编写语句使选中的项在数据库中都显示出来、怎么用SQL语句从数据库选择某个表中的第二条内容等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)