求个存储过程 比较简单的

luyuanshangao 2010-01-21 03:31:22
取出表A中Id为两位数的记录

取出表A中Id为四位数且前两位跟传进来的参数一样的记录

select * from A where len(id)=2
select * from A where len(id)=4 and left(id,2)=参数

拜托各位再帮忙把上面的两条sql写成个存储过程

参数 是ID
我的ID是01,0101,010101这样的分3级
如果传进来的ID参数ID=01 就找到0101 如果是0101 就找到010101

拜托了
...全文
93 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
luyuanshangao 2010-01-21
  • 打赏
  • 举报
回复
谢谢各位了
yjh53615728 2010-01-21
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 josy 的回复:]
SQL codecreateproc sp_test@sintasbeginselect*from tbwherelen(id)=len(@s)+2andleft(id,len(@s))=@send
[/Quote]

树哥正解
yjh53615728 2010-01-21
  • 打赏
  • 举报
回复

CREATE PROC sp_test(@ID INT)
AS
BEGIN
SET NOCOUNT ON
SELECT * FROM A WHERE ID=@ID OR (LEN(ID)=4 AND LEFT(LTRIM(ID),2)=@ID) OR (LEN(ID)=6 AND LEFT(LTRIM(ID),2)=@ID)
SET NOCOUNT OFF
END
黄_瓜 2010-01-21
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 luyuanshangao 的回复:]
那样不行吧 我是要一次取出一个ID级别的记录 比如说0101、0102这样的 不要取出01或010101的记录
[/Quote]
create proc p 
@s int
as
begin
select * from A where len(id)=len(@s)
union all
select * from A where len(id)=len(@s)+2 and left(id,2)=@s
end
百年树人 2010-01-21
  • 打赏
  • 举报
回复
create proc sp_test @s int
as
begin
select * from tb where len(id)=len(@s)+2 and left(id,len(@s))=@s
end
itliyi 2010-01-21
  • 打赏
  • 举报
回复
chuifengde 2010-01-21
  • 打赏
  • 举报
回复
create proc proc_test
@id varchar(20)
as
select * from [Table] where len(id) between len(@id) and len(@id)+3 and left(id,2)=@id
luyuanshangao 2010-01-21
  • 打赏
  • 举报
回复
首先要判断传进来的Id是几位数的 如果是2位数的 那就要取Id为4位数的记录 且最前面两位必须是跟传进来的Id相同
--小F-- 2010-01-21
  • 打赏
  • 举报
回复
create proc f
(
@id varchar(20)
)
as
select * from [Table] where len(id)>len(@id) and left(id,2)=@id
nianran520 2010-01-21
  • 打赏
  • 举报
回复
create proc proc_getdata @id varchar(30)
as
begin
select * from tb
where len(id) = len(@id)+2 and left(id,len(@id))=@id

end
chuifengde 2010-01-21
  • 打赏
  • 举报
回复
create proc proc_test
@id varchar(20)
as
select * from [Table] where len(id)>len(@id) and left(id,2)=@id
luyuanshangao 2010-01-21
  • 打赏
  • 举报
回复
那样不行吧 我是要一次取出一个ID级别的记录 比如说0101、0102这样的 不要取出01或010101的记录
黄_瓜 2010-01-21
  • 打赏
  • 举报
回复
create proc p 
@s int
as
begin
select * from A where len(id)=2
union all
select * from A where len(id)=4 and left(id,2)=@s
end
大家这么喜欢,我就不要资源分了,改成0分了,我为我一己私利感到抱歉…… MongoDB学习手册 ......................................................................................................................... 1 说明.......................................................................................................................................... 2 一、 Mongodb简介 .......................................................................................................... 4 二、 MongoDB特性 ......................................................................................................... 5 适用场景: ....................................................................................................................... 5 不适用场景: ................................................................................................................... 6 三、 MongoDB的工作方式.............................................................................................. 6 四、 MongoDB的下载 ..................................................................................................... 8 五、 MongoDB的安装 ..................................................................................................... 9 六、 MongoDB数据类型................................................................................................ 12 1. Timestamp类型 ...................................................................................................... 12 2. ObjectId类型 .......................................................................................................... 12 3. 数据库关联 ............................................................................................................. 14 七、 GridFS文件系统 ..................................................................................................... 15 八、 索引 ......................................................................................................................... 16 九、 主(Master)/从(slave)数据库同步 ................................................................ 20 1. 建立主/从服务器 ................................................................................................... 20 2. 相关参数说明 ......................................................................................................... 21 3. Slave顶替Master ................................................................................................... 22 4. 切换Master/Slave角色 ......................................................................................... 22 5. 更新主服务器位置 ................................................................................................. 22 十、 MongoDB分片和集群............................................................................................ 24 1. 简单分片实例 ......................................................................................................... 24 2. 高级分片实例 ......................................................................................................... 29 十一、 数据库基本操作:增查删改 ............................................................................. 37 1. Insert ....................................................................................................................... 37 2. Query ....................................................................................................................... 38 3. Remove.................................................................................................................... 52 4. Update ..................................................................................................................... 53 十二、 Shell控制台 ........................................................................................................ 62 1. 执行.js文件 ............................................................................................................ 62 2. –eval ........................................................................................................................ 62 3. 脚本和互动的区别 ................................................................................................. 62 十三、 安全与认证 ......................................................................................................... 63 1) 开启安全认证 ......................................................................................................... 63 2) 添加用户 ................................................................................................................. 64 3) 认证 ......................................................................................................................... 64

34,837

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧